Legacy GM How to limit the jump?

Caio

Member
Hello,
when my character jumps, if I hold the jump key, it keeps jumping and going up, can anyone help me?
This is my code:
Code:
//Jump
if (key_jump)
    {vspd =-jumpspd
    }
    else
    {
        if (vspd <5)
            {vspd += grav;
            }
            if place_meeting(x,y,obj_ground)
                {vspd=0
                }
    }
thx
 

RangerX

Member
Right now, you're telling the engine that for as long as the key is detected, execute that code.
What you need to is check a keypress. The fact a key as pressed and not the fact its "on or off".

The function you need to use is "keyboard_check_pressed()"
 

Caio

Member
Right now, you're telling the engine that for as long as the key is detected, execute that code.
What you need to is check a keypress. The fact a key as pressed and not the fact its "on or off".

The function you need to use is "keyboard_check_pressed()"
thx! it worked, but when I press it repeatedly, it jumps up and up continuous
 
A

altan0

Guest
thx! it worked, but when I press it repeatedly, it jumps up and up continuous
You will need to add a jump state / flag to the if condition so it can check if the object has not jump then it executes the nested codes. The jump state resets when it hits the ground.
e.g. code

Code:
//create event
isjump = false;
Code:
//step event
//Do the floor check first before the key press check
if (place_meeting(x,y+1, obj_floor) && isjump == true) {
     isjump = false;
}

if (keyboard_check_pressed(vk_space) && isjump == false) {
    //jump codes here
     isjump = true;
}
 

Caio

Member
You will need to add a jump state / flag to the if condition so it can check if the object has not jump then it executes the nested codes. The jump state resets when it hits the ground.
e.g. code

Code:
//create event
isjump = false;
Code:
//step event
//Do the floor check first before the key press check
if (place_meeting(x,y+1, obj_floor) && isjump == true) {
     isjump = false;
}

if (keyboard_check_pressed(vk_space) && isjump == false) {
    //jump codes here
     isjump = true;
}
thx!!! It worked :D
 
Top