1
votes

I am making a very basic game sort of zelda esque, I am having some trouble implementing collisions with walls and how it interacts with the player however. I am using a simple AABB algorithm to detect the actual collision but how should the player object respond? If I set the speed vector to zero it will just stick to the object forever without being able to remove myself from the square. Reversing the speed will make the player character also reverse in the other axis potentially which is not ideal.

Any ideas on how to deal with this?

1
If the x + width is at the bounds, why not move it -1 in the x direction? This would remove it from the wall and allow the player to continue to move right, without having any effect. - Tas
see Responses section here gamedev.net/articles/programming/… - wtom

1 Answers

1
votes

You have a speed vector for your object. You can write this vector in the collision surface reference (see "change of basis"), you then have

  • A parrallel component to the surface
  • A perpendicular component to the surface

To have a simple bounce without friction, you just have to :

  • Keep the same parrallel component
  • Take the opposite of the perpendicular component.

You then just have to change your base back to the game referential and you're good. This also works in 3D.

Edit : note that if all your objects surfaces are vertical or horizontal, you may identify parallel and perpendicular components without any base change.