Simple Jumping Physics

So I’ve only made top-down games in the past, and I wanted to try a platformer. Unfortunately, I’m having trouble with jumping.
I don’t want to use an external physics library like JBox2D for my first platformer, just to get some experience in making simple 2D physics on my own. All I need is gravity that sucks the player down until they collide with a platform, and then being able to jump from that platform on to other platforms. Simple right? Well apparently it isn’t for me…

My game is tile based by the way. I need a way of checking if the player is “on the ground” before he/she can jump. For a tile based game, how would this work? I also need a way to actually “jump” if the player is indeed grounded.

The pseudocode would be like this:


if(!player.isGrounded()){
    applyGravity();
}else{
    if(jumpButtonPressed()){
        jump();
    }
}

So to conclude, I need to know how to check if the player is “on the ground” in a tile based game, and I need to know how to make the player jump if they are.

jumping and falling are both opposites represented by the objects velocity. if its not on solid ground, increase its downward velocity at a constant rate depending on how strong gravity is. when you jump, just set velocity to a high positive value and gravity will gradually curve it back down after its reached its apex.

as for checking if the player is on solid ground, you just have to work out which tile is below the feet and check if its solid or air. it helps to check under both feet, sometimes one corner of the sprite can be sitting on solid ground when the other isnt.

This might help.

Good luck with your game. :slight_smile: