How can i know if character landed on ground? and question number 2 - how use animation when character not moving

Hi Nice to find this community,

  1. Question #1
    can i know if character landed on ground?
    I found this example already
    How to catch when player hit the ground after jump

but its always returning false for some reason,
the specific code:

class SceneMain extends Phaser.Scene {
	// other methods
	update() {
		// code...
		// console.log( this.catCharacter.body.onFloor() ) - always returning false
		if( this.catCharacter.body.onFloor() ) {
			console.log('cat on ground');
		}
	}
	endJump() {
		console.log('endjump');
		this.timer.remove();
		this.catCharacter.setVelocityY(-350);
		this.power=0;
	}
	startJump() {
		console.log('startjump');
		this.timer=this.time.addEvent({ delay: 100, callback: this.tick, callbackScope: this, loop: true });
		// this.catCharacter.setVelocityY(-100);
	}
}

and uploaded whole code to github also
sceneMain.js - with jumping issue.

  1. Question #2
    I want change character when not moving:
    this how i tried to do it.
class SceneMain extends Phaser.Scene {
	// other methods here...
	update() {
		var key_right=this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.D);
		var key_left=this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.A);
		var key_up=this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.W);

		if ( key_left.isDown ) {
			if( this.catCharacter.flipX == false ) {
				this.catCharacter.flipX=true;
			}
			this.catCharacter.x-=2;
		}
		else if ( key_right.isDown ) {
			if( this.catCharacter.flipX == true ) {
				this.catCharacter.flipX=false;
			}
			this.catCharacter.x+=2;
		}
		else {
			// relevant code for cat idle animation 
			console.log('cat idle');
			this.catCharacter.setTexture('cat_idle_1');
		}
	}
}

again the same full scene is here:

Thanks a lot guys!!!

anyone help please :slight_smile:

Use body.touching.down. onFloor() is for contact with static bodies.

if (key_left.isDown) {
  this.catCharacter.flipX = true;
  this.catCharacter.x -= 2;
  this.catCharacter.play('catRun', false);
} else if (key_right.isDown) {
  this.catCharacter.flipX = false;
  this.catCharacter.x += 2;
  this.catCharacter.play('catRun', false);
} else {
  this.catCharacter.play('catIdle', false);
}