Basic Jump Physics
Monkey Forums/Monkey Beginners/Basic Jump Physics
| ||
Hello, I am new to programming and am attempting to set up a basic run/jump game with maybe a double jump using monkey/mojo. I've gone through all of the Tutorials Jim so kindly posted but am having trouble creating the physics for the jump w/ gravity. If anyone has suggestions of the best code for it I would be greatly appreciative! I did figure out how to make the background tile and move with the increasing speed though! one step at a time right! -Derek |
| ||
You can use basic Newtonian physics. Store position and velocity vectors, and apply an acceleration vector on every update. If your updates are rapid, the following calculations will do: velocity += acceleration * dt position += velocity * dt [I left out some small corrections that you probably won't need] Gravity is simply a constant acceleration in the downward direction. Jumps are most easily handled as impulses, i.e. a sudden step change applied to velocity. As for your length units, you should probably define them as a fixed fraction of the screen width, rather than pixels. This should at least give you something workable, though possibly not perfection. |
| ||
Please read these posts on vectors and matrix operations... http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-1/ http://blog.wolfire.com/2009/07/linear-algebra-for-game-developers-part-2/ http://blog.wolfire.com/2010/07/Linear-algebra-for-game-developers-part-3 |
| ||
Cool! The linear algebra super helps. Thanks! |
| ||
good!!! |