Skip to main content
GameDev.net gamedev.net
🔒 Locked

math behind a jump routine

Started by cc_indrema Jan 15, 2002 at 7:14 AM 2 replies 250+ views
Original Post
cc_indrema
cc_indrema
my first jump n run is done. but i want to improve the jump routine. so how does the jump routine math behind an oldschool jump n run look like? thanks for your help.
CaptainJester
CaptainJester
This sounds like it is for 2D, so that is what I will deal with.

What you need are three values, two for velocity and one for acceleration. Your acceleration value will be the gravity constant. In the real world, this is 9.8 metres/second/second(32 feet/second/second). This is basically saying that your velocity will increase in the direction of the acceleration by 9.8 metres/second each second. In this case, since the acceleration is positive, the direction is down(Y axis). When a jump is performed, there is an instantaneous acceleration in both the X and Y direction. This is added to the X and Y velocities to start the jump. The X velocity will remain constant, until the character lands. The Y velocity will be affected by acceleration due to gravity until the character lands. The easiest way to implement this is to add the acceleration due to gravity component every turn. This way, even if the character does not jump, but walks off a ledge, he starts to fall. What you do is add the accel to velocity, check to see if there is an obsticle in the path, if there is, zero out the velocity. This way, you make gravity a constant part of the game and it will automatically affect your jumps.

If you want to get more complicated, you can always add wind resistance, various levels of friction on the take off surface. You can then affect the jump with these other factors. But just adding the gravity constant will give your jump that nice arc effect. Also since this is probably not a 3D FPS or anything like that, accuracy with gravity is not a must. Just pick a number that will look good. Don''t forget to time slice it to the number of frames per second you are running.

---
Make it work.
Make it fast.

"Commmmpuuuuterrrr.." --Scotty Star Trek IV:The Voyage Home
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][
Promit
Promit
You have an acceleration vector which is -9.8 meters per second(or 32 ft/s). THus you give the character an initial velocity in m/s and decrease his velocity by 9.8 m/s in the vertical direction. The horizontal direction is unaffected by the vertical direction. Obviously, the horizontal speed should be the horizontal component of the initial velocity vector, and should not change until the character reaches the ground, at which point the character should probably stop.

If you aren''t too aware of basic vector math, say so and ill explain it more simply.

-----------------------------
The sad thing about artificial intelligence is that it lacks artifice and therefore intelligence.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.