Platformer Game Physics

closed account (2NywAqkS)
In a simple platform game I'm making, when the player lands after he jumps he goes a small amount into the floor (or platform). I understand this is because his downward velocity per frame is not perfectly rounded to the y coordinate of the floor.

Although I understand the problem I'm not sure how to fix it. I could work out the players next position and only move to it if it isn't under the floor's y position, but that would result in the player landing slightly above the floor.

Is there a way to make the player always land precisely on the floor?

Any help is much appreciated.
Thanks,
Rowan.
Last edited on
Test for the players next position, and if it is below the floor, move him to the floor.

EDIT:

to back up my point (realizing it might be unclear)
1
2
3
4
5
6
7
8
9
void movementFunction()
{
    player.y = someCalculationToGetNewPosition;

    if(player.y < floor.y)
        player.y = floor.y

    drawScreen(); 
}
Last edited on
Yeah. Instead of moving them all the way into the floor or simply not moving them (so they are floating) move them until they hit the floor.
Topic archived. No new replies allowed.