#### CrimsonAU

##### Member
I need some help programming a double jump, I've seen several solutions posted before however I was hoping to have a double jump that also allows an 'air jump' of sorts after falling off of a ledge. Additionally, I am using Shaun Spalding's tutorial code for basic vertical and horizontal movement.

So far my normal jump and vertical movement looks like:
if (place_meeting(x,y + 1,oWall)) and (key_jump)
vsp = -9.6;

if !(key_jump) && vsp < 0
vsp = vsp * 0.6

if (place_meeting(x,y + vsp,oWall))
{
while(!place_meeting(x,y + sign(vsp),oWall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;

And my double jump / air jump looks like:

if (place_meeting(x,y + 1,oWall))
state = 0;
djumpused = false;

if (hasdjump == true) and (djumpused == false) and !(key_jump) and !(place_meeting(x,y + 1,oWall))
state = 1;

if (state == 1) and (key_jump)
{
//Smaller jump, state set to non double jumpable, double jump has been used
vsp = -7.6;
state = 0;
djumpused = true;
}

djumpused tracks whether or not the player has used their double jump, and is created as false.
state tracks whether the player is currently able to double jump, which is meant to be when they are falling and not holding the jump key - 0 if unable, 1 if able
hasdjump tracks whether or not the player has picked up the double jump power-up.

The issue is that the player is able to jump indefinitely in the air, while I want the code to be able to prevent further jumps in the air until the player has landed on the ground.
Any help would be greatly appreciated.

Last edited:

#### Roman P.

##### Member
Just have a variable to check what stage of the jump youre in

jump = 0/false when on ground
when jumped from ground or fell off ledge change it to 1
when in second jump change it to 2

#### CrimsonAU

##### Member
Just have a variable to check what stage of the jump youre in

jump = 0/false when on ground
when jumped from ground or fell off ledge change it to 1
when in second jump change it to 2
I've tried to do this to a lesser extent by having a variable to check when I am on ground and when I am able to start my second jump, but for some reason it always seems to think I am able to start second jump - I've drawn my variables to the screen and it seems that 'djumpused' is always false except for the exact frame I use my second jump