hello, I am trying to use the rotateTo command rotateTo api but I cannot figure out how to use it. If anyone could give an example, that would be great. I am also trying to set the shortestPath parameter to true.
this.tweens.add({
targets: place.cameras.main,
rotation: -name.angle * Math.PI/180,
duration: 500,
shortestPath: true
});
This rotates the camera to where I want but it does not use the shortest path. How do I make it use the shortest path?
// Target rotation in radians (e.g., 180 degrees)
let targetRotation = Math.PI;
// Get the current rotation of the camera
let currentRotation = this.cameras.main.rotation;
// Calculate the shortest path to the target rotation
let shortestPath = Phaser.Math.Angle.Wrap(targetRotation - currentRotation);
// Tween the camera to rotate using the shortest path
this.tweens.add({
targets: this.cameras.main,
rotation: currentRotation + shortestPath,
duration: 2000, // Duration in milliseconds
ease: 'Linear', // Easing function
onComplete: () => {
console.log('Camera rotation complete!');
}
});
works very well if you want the rotation to be shorter change the duration. I dont think you need the ease tween though.
this.cameras.main.rotateTo(3.14, true)