# Switching Animations

**URL:** <https://phaser.discourse.group/t/switching-animations/962>\
**Category:** Phaser 3\
**Created:** [January 27, 2019, 2:02am UTC](https://phaser.discourse.group/t/switching-animations/962 "2019-01-27T02:02:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nivlecs](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/nivlecs/32/530_2.png) [@Nivlecs](https://phaser.discourse.group/u/Nivlecs)\
**Post date:** [January 27, 2019, 2:02am UTC](https://phaser.discourse.group/t/switching-animations/962/1 "2019-01-27T02:02:33Z")

</div>

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);
```

---

<div class="post-metadata">

**Author:** ![paynterc](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/paynterc/32/4430_2.png) [@paynterc](https://phaser.discourse.group/u/paynterc)\
**Post date:** [November 10, 2021, 3:19am UTC](https://phaser.discourse.group/t/switching-animations/962/2 "2021-11-10T03:19:28Z")

</div>

You probably want to user Angle.BetweenPoints. Either way, the return value will be in radians, not degrees, so you need to convert to degrees to get values like “-70”.

Also in your if statement you have to check the degrees against both conditions. You can’t say “if(Deg \>= -70 && \<= 70)” or you’ll get a syntax error.

let Rad = Phaser.Math.Angle.BetweenPoints(this.player, transformedPoint);  
let Deg = Phaser.Math.RadToDeg(Rad);  
if(Deg \>= -70 && Deg \<= 70 ){// do stuff }

[https://jsfiddle.net/paynterc/830yu49n/5/](https://jsfiddle.net/paynterc/830yu49n/5/)
