How to catch when player hit the ground after jump

Hey guys, i’m doing this game that uses animations like parkour movements. So the landing animations after the jump are very important for the game’s plot.

Currently i’m having this issue for trigger the animation of landing/rolling after the player jump or fall, and, in fact i don’t know the best way/logic to do it.

My actual code (only an idea):

function update(){
    // ... 
    if (!player.body.touching.down){        // while player's in the air
        if (player.body.touching.down){     // when player hit the groud
            player.setVelocityX(0)
            player.anims.play('land')       // play landing animation
        }
    }

Obviously doesn’t work…

So, can one of you guys help me with the code or logic or the best way to identify when the player hit the ground?

Hi @motylera,
To detect the firs touch on floor after a jump try this code:

if(player.body.deltaY() > 0 && player.body.onFloor()){
		// Your code
	  }

Regards.

1 Like