Enemy patrol

I’m trying to make an enemy patrol, I need to track the end and start points of the path, but all I got was, help (

  create() {
    path = new Phaser.Curves.Path()
    path.lineTo(100, 0)
    follower = this.add.follower(path, 100, 100, 'enemy').startFollow({ duration: 3000, loop: -1, yoyo: true, positionOnPath: false, rotateToPath: false })
}
  update() {
    let tan = path.getTangent(follower.pathTween.getValue())
    if (tan.x > 0) follower.setFlipX(false)
    else if (tan.x < 0) follower.setFlipX(true)
}

What do you want to happen?

I need the sprite to move from point A to point B, at point B turn around to point A and back

And what happens now?

Снимок экрана_20230221_232717
Nothing, doesn’t work, just 1

It’s moving correctly but there’s no flipping.

if (follower.pathTween.data[0].state === Phaser.Tweens.PLAYING_BACKWARD) {        
    tan.scale(-1);
}
1 Like

if (follower.pathTween.data[0].state === Phaser.Tweens.PLAYING_BACKWARD)
wow it worked, thanks!