Legacy GM Best wat to make a long jump mechanic

K

koopy eacret

Guest
Okay...I am making A Platformer and and i want a mechanic so when you just tap the jump button you do a small jump and when you hold down the jump button you jump much higher...
So Just Like Two JUMP Heights but you can kinda choose which one you need for this said part of the game
 
K

koopy eacret

Guest
This might help...
I Have used this in the past... and its not what I'm looking for

this video is like "the longer you hold jump, the higher you jump" BUT What I'm looking for is"when you just tap jump you do a jump at the value of 'x' "

BUT If you hold it down and you going up and your still pressing it and you did not let go for the entire thing then jump at a value of 'x'
 
J

joqlepecheur

Guest
Are you saying you want the character to reach a more distant place but not go higher ?

If this is what you want, you can play with the gravity once you are at the peak of your jump (when going down).
If you go down slower, you will land further.

When you jump you put a variable is_holding = 1 ;
If you release button then is_holding = 0 ;
And when going down you apply a little less gravity if is_holding == 1 ;
 

samspade

Member
I Have used this in the past... and its not what I'm looking for

this video is like "the longer you hold jump, the higher you jump" BUT What I'm looking for is"when you just tap jump you do a jump at the value of 'x' "

BUT If you hold it down and you going up and your still pressing it and you did not let go for the entire thing then jump at a value of 'x'
As worded this doesn't make a lot of sense as it would require the game to know at the start of the jump that the player didn't let the button go for the whole jump which is impossible. I think a version of the Spalding tutorial is what you have to shoot for but as joqlepecheur points out there are lots of ways you could modify it. You could modify gravity or horizontal speed. If all you want is two specific heights or lengths then you could simple calculate one jump height for a press of a button and another value for a held if it held for x frames. Again though, since the game won't know that the player is going to continue holding down the button after the jump starts you will have to code some type of increase/modification as the jump continues.

Edit: For example

Code:
if (jump) vsp = -jumpspeed; //set to longest jump
if (jump_held) long_jump += 1;
if (vsp < 0) && (!jump_held) {
    if (long_jump < 10) {
        vsp = max(vsp, -jumpspeed / 2) //code for short jump
    }
}
With this code you will start jumping as soon as you push jump to the farthest distance. If you release the jump key to quickly however, it will cut your jump short. Unlike the code in the tutorial, this code won't be a gradient past a certain point. In other words, Spaldings code has a minimum (short jump) but letting go at any point will stop you. This code has a minimum, but letting go past the minimum still performs the long jump. Note that you would need to reset the long_jump counter somewhere.
 
Last edited:
Top