Jump to content
Sign in to follow this  
RSS Bot

Tursi's Blog - How to Jump

Recommended Posts

HOW TO JUMP
Ever fired up a platformer, and thought "Damn, this looks great! But why does the player hover when I jump??"

It's a very common thing for developers to not really understand how jumping works, and to simply code a fixed speed up for a few frames, then a fixed speed down. The net effect is a very unnatural motion, and if the player is falling, they look more like they are levitating. (REALLY lazy ones might just pop the character into the air for a few frames, then pop them back down. That looks more like an old LCD game.)

It's a shame, because simulating a realistic jump is not only very easy to do, it adds greatly to the playability of your game. The motion feels more natural and the player will be able to instinctively predict the motion.

In real life, all things are affected by the pull of gravity. But what is gravity? Nobody actually knows. But the EFFECT is very predictable -- a constant acceleration towards mass. In the case of standing on planet Earth, the average effect is an acceleration of 9.8m/s^2 towards the center of the planet. (Of course, if you are standing on something and not falling, the acceleration is blocked - but it's that force that keeps you stuck there.)

The word "acceleration" is key. And this is really easy to put into code.

The really simple jump function probably looks something like this:

 
But we don't move like that in the real world. What happens when we jump? We tense our muscles, and push upwards as hard as we can. After that point, the acceleration of gravity does the rest - there is no "timer", the length of time we are in the air depends on how hard we start -- that is, our initial velocity. We can simulate that almost as simply as above, and get much more realistic movement.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...