side scroller jumping algorithm
I''m working on a 2d side scroller and I would like to know if anyone knows of a good jumping algorithm.
Any help would be apperciated.
the easiest way is to define a constant graivity. this could be changed to whatever looks good. then when the player jumps, add 5 or something to his y velocity, (x velocity is independant of y velocity) and subtract the gravity factor each frame.
My Homepage
My Homepage
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
a jumping algorithm... nice name for it.
anyways this is what i would do:
you have a variable for vertical velocity (should have one for horizontal too but we won''t worry about that). Every frame decrease this vertical velocity, which is in essence simulating gravity. However if you are standing on something, then set the vertical velocity to 0 becuase you aren''t moving. When you jump, simply make the vertical velocity some positive number, the simulated gravity will bring the character back down until it is once again on the ground, and the vert velocity will be 0 again. Heres some pseudocode:
vvelocity -= 2; //gravity
if (onground)
vvelocity = 0;
if (hitjumpkey)
vvelocity = 10;
ycoord -= vvelocity; //-= because of the whole 0 at top 480 on bottom deal
anyways this is what i would do:
you have a variable for vertical velocity (should have one for horizontal too but we won''t worry about that). Every frame decrease this vertical velocity, which is in essence simulating gravity. However if you are standing on something, then set the vertical velocity to 0 becuase you aren''t moving. When you jump, simply make the vertical velocity some positive number, the simulated gravity will bring the character back down until it is once again on the ground, and the vert velocity will be 0 again. Heres some pseudocode:
vvelocity -= 2; //gravity
if (onground)
vvelocity = 0;
if (hitjumpkey)
vvelocity = 10;
ycoord -= vvelocity; //-= because of the whole 0 at top 480 on bottom deal
~EODCyismARDEM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement