How to detect when player lands

HuntExe

Member
How would I detect when the player has just landed on the ground, not when the player is just standing on a platform at any time.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Keep track of whether the player was on the ground in the previous step. If it wasn't in the previous step but now is, it just landed.
 

Gizmo199

Member
When your player is on floor, check the vspeed before setting it to zero.
Example:

GML:
if ( !place_meeting(x, y+1, obj_ground)){
    vspeed += gravity;
} else {
    if ( vspeed > 0 ){
    
        // LANDED
        
        vspeed = 0;
    }   
}
 

HuntExe

Member
Keep track of whether the player was on the ground in the previous step. If it wasn't in the previous step but now is, it just landed.
Sorry, could you specify a little more? I'm a little lost. I assume you would set a variable in the begin step event but I'm not sure.
 
Last edited:

TsukaYuriko

☄️
Forum Staff
Moderator
The Begin Step event has nothing to do with this. All you need is to do things in the right order... :)

As in, create two variables, previous and current, but give them more descriptive names than that.
Every step, set previous to current.
Then - and it's important to keep the order exactly like this - set current to the result of a check whether there's solid ground below you.

This means that current now carries the value that corresponds to the current step, but previous now carries the value that corresponds to the previous step. That's because you just set it to current (which was last updated in the previous step, but not yet in this step) and only then updated current so that it now carries the current step's value.


You can now tell which state you're in based on the values of these two, e.g.
false / false: You weren't on the ground and still aren't - You're in the air
false / true: You weren't on the ground and now are - You just landed
true / true: You were on the ground and still are - You're on the ground
true / false: You were on the ground and now aren't - You just jumped or walked off a cliff
 
Top