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.
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: