Hey thanks.
I have been trying to solve this now for two days and its doing my head in…
I went away from that method above because while I sussed out how to accelerate the player rotation in the direction of the mouse, I struggled to work out when to Start a Decelerate.
Also that the tween doesn’t keep restarting when the mouse is moved.
So then I tried something else.
This results in Smooth Rotation until it hits -180 / 180 then bounces…
Tween in Create
AngleTween = this.tweens.add({
targets: player,
angle: 0,
ease: ‘Sine.easeInOut’,
duration: 400,
});
Then in Update
var PlayerPosX = player.body.position.x
var PlayerPosY = player.body.position.y
var MousePosX = this.cameras.main.scrollX + game.input.mousePointer.x;
var MousePosY = this.cameras.main.scrollY + game.input.mousePointer.y;
var RotTargetAngle_RADS = (Phaser.Math.Angle.Between(PlayerPosX, PlayerPosY, MousePosX, MousePosY));
var RotTargetAngle_DEGS = parseInt(RadToDeg(RotTargetAngle_RADS));
var playerAngle_DEGS = parseInt(player.angle);
var diff = RotTargetAngle_DEGS - playerAngle_DEGS
if (diff < -180) {
diff = diff + 360;
} else if (diff > 180) {
diff = diff - 360;
}
AngleTween.updateTo(‘angle’, playerAngle_DEGS + diff, true);
AngleTween.restart();
Something about the UpdateTo tween is causing it bounce when it hits the 180 / -180 point.
If you ignore the tween and just set the player.angle e.g.
player.angle = playerAngle_DEGS + diff, then it gets past the 180 point, but you lose the smooth rotation.
My heads hurting
Any advice appreciated.