Hey there,
I’m not sure how to do this correctly but currently I have my sprite following my mouse pointer’s movements and I want to change my character’s animation depending on the angle between the sprite and the mouse pointer. This is what I have so far. I probably got the if statement wrong…
this.cameras.main.startFollow(player); //camera follows player
this.input.on('pointermove', function (pointer) {
//converting canvas coordinates to world coordinates
const transformedPoint = this.cameras.main.getWorldPoint(pointer.x, pointer.y);
//slime follows the mouse pointer
this.physics.moveToObject(this.player, transformedPoint, 240);
if(Phaser.Math.Angle.Between(this.player, transformedPoint) >= -70 && <= 70) {
this.player.flipX = false;
this.player.play("walkright");
} else if(Phaser.Math.Angle.Between(this.player, transformedPoint) <= 110 && >= 110) {
this.player.flipX = true;
this.player.play("walkright");
} else {
this.player.play("walkdown");
}
}, this);