Variable Jump Height

How to I make my 2d platformer so when I hold A, the player jumps higher, but a short tap makes the player jump lower?
If you know the game Celeste, or Hollow Knight, this is a feature, and i want to add it to my game, its a usefull mechanic for platformers

3 Likes

You could make it so that each second that the A button is pressed, the characters y-velocity decreases. This means short presses result in less upward speed, but long ones result in more. You would also want to add that on the A button being released, velocity should return to normal!

1 Like

the microsoft/arcade-platformer extension has this functionality built in!

also has a lot of other niceties like ā€œcoyote timeā€ and a grace period for jump button presses

3 Likes

can you show me how to do this?

1 Like

If you send the code yeah, did you mean my or richard’s solution?

richards sorry.
i got the arcade-platformer extensions loaded but its really confusing to use.

1 Like

I also am looking for a solution to this. I have been trying to get the extension to work also. When I load it it comes with a bunch of errors in the physics.ts and doesn’t load any blocks. I’ve tried loading the demo but there is no code inside and nothing runs.

1 Like

I tried doing this in my own game, and it worked perfectly! However, the sudden ā€œstopā€ of the y velocity is quite annoying, to say the least. Is there any way I could smoothen out the velocity when stopping the jump? Also sorry for reviving this old topic

1 Like

Sorry for late reply - Yeah! You could add that instead of immediately returning the y-velocity to normal, you could slowly turn it to normal over a period of maybe half a second. Something like a repeating block that continually averages the old y-velocity and the normal one would create a nice curve!

1 Like

Could you show me an image on how to make that? I’m kinda confused…

1 Like

Sure!
Press B to activate the new kind of jumping I mentioned.
It averages the y-velocity and the desired y-velocity (16 in this case) 5 times to make a gradual change, then sets it back to 16. You can play around with the values to get a better effect as well.

2 Likes

Uh, this is great and all, but two things. One, pressing B does nothing, I think you meant press A. And two, I meant a smooth change in y velocity like the robot gamemode from Geometry Dash. Thanks for helping anyways!

Oh yeah! I looked it up, I think this is what you mean:

A to jump again- in an actual game, you might want to put a limit on the ā€˜press’ variable to avoid huge jumps, and obviously not let them jump mid-air!

1 Like

Thanks! This was exactly what I wanted!

How to do this though?

1 Like

Maybe only let the ā€˜press’ variable increase when it is less than a certain number?

platformer… extension? so, i didn’t have to code that myself?

am i an idiot?

oh god, i think im an idiot… Screenshot 2024-04-21 173435

4 Likes

No you fine
If you want custom dashes and stuff you need your own

Knowledge! Learning! :sparkles: the memory of this fun discussion! :sparkles: