Hi there i have collision detection but i dont know how to stop object after collision and then move backward for example
any ideas ?
|
Hi there i have collision detection but i dont know how to stop object after collision and then move backward for example any ideas ? |
|||||||||||
|
|
In addition to Marton's answer you could also let your object "bounce" off the wall by reflecting its velocity vector:
example usage could be:
|
|||
|
|
A simple solution would be to implement a check during your movement code. If the player attempts to move right, check if there is an object that would stop the object moving in that tick and if so move the player next to that object and set the velocity to 0. For example:
|
|||
|
|
|
There are many solutions, depending on what kind of effect you want to achieve. Here's a simple 'rebound' solution: When a collision between object 'A' and the wall is detected, do the following:
|
|||||||||||
|