#### Archived

This topic is now archived and is closed to further replies.

# math behind a jump routine

This topic is 6005 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
Just do what all good game programmers do, fudge it!

That is unless you are doing something that require it to be percise!

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631434
• Total Posts
3000050
×