🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to add a double jump feature?

Started by
4 comments, last by a light breeze 3 years, 7 months ago

I am making a 2d platformer (code is here: https://github.com/LieutenantLark/2d-game)​ and i was thinking of adding a double jump feature that only works if the player is in the air, and there is a cooldown of 500ms (to avoid infinity jumps)
how can i make this a reality?

Advertisement

help yourself, it's all in there:

it's coded in csharp, but just follow what he does with the input key in code, the allow-to-jump, etc…

i leave it as an exercise for u to code it in javascript , should be a breeze for a keen coder of your abilities ?

if u want sliding movement, u can look here: https://paladin-t.github.io/articles/smooth-tile-based-movement-algorithm-with-sliding.html

have fun ?

@ddlox im coding in javascript, and its a 2d platformer

updated ?

A time-based cooldown is probably the wrong approach. The expected behavior of double-jump is that you get exactly one air-jump for each time you leave the ground. This is also easier to code than a timer: just have a boolean variable for if you still have an air-jump available, clear it when the air-jump is activated, and set it when you hit the ground.

This topic is closed to new replies.

Advertisement