Advertisement

How to add a double jump feature?

Started by November 23, 2020 10:14 PM
4 comments, last by a light breeze 4 years 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?

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 ?

Advertisement

@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