I am working on platformer game and I want to do basic collision with platforms, sadly still can't do it properly. Player movement is calculated like this:
velocity += acceleration
position += velocity + 0.5 * acceleration
All variables are vectors with x and y value. This works as expected, problem is with collision. My rules are:
- Stop falling when land on platform.
- Start falling when run from platform.
- Stop moving upwards when hit a platform during jump.
- Stop moving to side when hit wall, but be able to move to opposite direction.
Checking if bottom collide with platform is quite simple, but tricky part is detect, which side collided with platform and be able to set proper position for player.
I was trying to detect corners and middle from every side, but since my speed is not 1px per frame, sometimes player fall to quick and was detected as side as well.
What is good approach to detect which side collided?