# <SOLVED> How would I make my character perform a double jump?

M

#### marioman237

##### Guest
I want my character to have the ability to double jump, but I'm not sure how to go about it.

This is my Step event:

Code:
``````//Inputs
//Inputs

key_right = keyboard_check(ord ("D"));
key_left = -keyboard_check(ord ("A"));
key_jump = keyboard_check_pressed(ord ("W"));
key_fall = keyboard_check_pressed(ord ("D"));

//Smooth Movement

move = key_left + key_right;

if(move = -1){
hsp = approach(hsp,negmovespeed,aSpeed); //left
}
else if(move = +1){
hsp = approach(hsp,movespeed,aSpeed); //right
}else{
hsp = approach(hsp,0,dSpeed); //decceleration
}

//gravity
if (vsp < 10) vsp += grav

//Jumping and Quick Landing (My attempt at double jumping)
if (grounded <2)
{
if (key_jump = 1)
{
vsp = key_jump * -jumpspeed
grounded += 1
}
}

vsp+=grav;

//Horizontal Collision
if place_meeting(x+hsp,y,grassfloor)
{
while (!place_meeting(x+sign(hsp),y,grassfloor)) x+=sign(hsp);
hsp = 0;
}

x = x + hsp;

//Vertical Collision
if place_meeting(x,y+vsp,grassfloor)
{
while (!place_meeting(x,y+sign(vsp),grassfloor)) y+=sign(vsp);
if (sign(vsp) == 1)
{
grounded = 1;
}

else
{
grounded = 0;
}
vsp = 0;
}

y = y + vsp;``````
I'm using grounded as a check for how many jumps the player has used

0 means they are on the floor
1 means they have used one jump
2 means they have used two jumps

M

#### marioman237

##### Guest
This was solved in the Discord server

This is the fixed code, replacing Grounded with Jumps_Left

Code:
``````//Inputs

key_right = keyboard_check(ord ("D"));
key_left = -keyboard_check(ord ("A"));
key_jump = keyboard_check_pressed(ord ("W"));
key_fall = keyboard_check_pressed(ord ("D"));

//Smooth Movement

move = key_left + key_right;

if(move = -1){
hsp = approach(hsp,-movespeed,aSpeed); //left
}
else if(move = +1){
hsp = approach(hsp,movespeed,aSpeed); //right
}else{
hsp = approach(hsp,0,dSpeed); //decceleration
}

//Jumping
if (jumps_left >0)
{
if (key_jump == 1)
{
vsp = key_jump * -jumpspeed
jumps_left -= 1
}
}

//gravity
if (vsp < 10) vsp += grav

vsp+=grav;

//Horizontal Collision
if place_meeting(x+hsp,y,grassfloor)
{
while (!place_meeting(x+sign(hsp),y,grassfloor)) x+=sign(hsp);
hsp = 0;
}

x = x + hsp;

//Vertical Collision
if place_meeting(x,y+vsp,grassfloor)
{
while (!place_meeting(x,y+sign(vsp),grassfloor)) y+=sign(vsp);

jumps_left = 2;
vsp = 0;
}

y = y + vsp;``````