Sign in to follow this  
ChrisRX

Jumping in a 2d platformer

Recommended Posts

In a platformer that I'm currently coding, the gravity is simply calculated as a constant velocity downwards until it collides with a tile. With this though, I don't know how to implement jumping. Obviously if I define gravity as a function of acceleration, then I just give the character a negative downwards velocity and it will work. Is this the way that most people code this though? Or do people tend to use some other short cut?

Share this post


Link to post
Share on other sites
No, that's pretty much how it's done. That is by setting a negative velocity when jumping, and continually adding the gravity constant to that each frame to get a nice parabola. Add in some simple (unaccelerated) movement on the x axis independently controlled by the joystick, include some collision detection to snap your character to the ground (and reset the velocity) and you've got basic platform game movement right there.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this