Skip to main content
gamedev.net
🔒 Locked

Variable Jump??

Started by patroclus02 3 replies 750+ views
Original Post
patroclus02
patroclus02
I''m programming a 2d-platforms game, and I''m almost finished with game engine. Only two main things left, and one of them is a variable jump, depending on how long user presses jump button. Now I have a fixed-jump, making sprite''s Y speed high, and letting gravity engine slow down to a parabollic fall. How could I implement easily a variable jum??? Thanks a lot!
Timbatron
Timbatron
I think the way games like mario did it is to not allow gravity to work until you let go of jump (up to a certain limit). That means the speed will be constant up until the jump button is released, which makes the height jumped fairly proportional to the amount of time pressed, plus it keeps the jumps consistently parabolic (except while jump is being held). In pseudo-code, if(jumpIsPressed && pressedTime < (.3 * seconds) ) ySpeed = 32;

[edited by - timbatron on November 22, 2003 9:53:10 PM]
My Page : http://acidbase.computed.net
SpaceDude
SpaceDude
yeh or you could even make the speed increase as you hold it up to a limit
RhoneRanger
RhoneRanger
Well, that is not natural since the speed is at maximum at the point of escaping gravity.

One way to do it is this (pseudocode)

#define X your jump velocity

float JumpVelocity = X;

if ( jumpKeyPressed && JumpVelocity > 0 )
{
JumpVelocity -= your gravity constant ;
}
else if ( jumpKeyReleased )
{
JumpVelocity = 0;
}

Do your physics here

if( JumpVelocity == 0 )
{
JumpVelocity = X;
}
TechleadEnilno, the Ultima 2 projectwww.dr-code.org/enilno
patroclus02
patroclus02
Thanks you all.
I''m using RhoneRanger solution for the moment, and it is working great. I think it is more realistic than the others, though realism isn''t most important thing in platforms game, but also it does not require a counter to check how much time key has been pressed.

Anyway I find Timbatron'' solution really good for this kind of application

Topic Locked

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

Sign in to reply to this topic.