Question by
elucard_ · Feb 06 at 12:57 PM ·
rotationquaternionmatheuleranglesquaternion.slerp
Rotate clockwise/counterclockwise using Quaternion.Slerp()
I am using Quaternion.Slerp() to rotate an object towards player's rotation on Y axis. But if the player's rotation goes too far it changes the direction to take the shortest path. I want to rotate the object clockwise if the player is rotating clockwise and vice versa. Here's the code:
void FixedUpdate()
{
transform.position = new Vector3(follow.position.x + posOffset[0], follow.position.y + posOffset[1], follow.position.z + posOffset[2]);
Quaternion followRotation = Quaternion.Euler(new Vector3(followRot.eulerAngles.x + rotOffset[0], followRot.eulerAngles.y + rotOffset[1], followRot.eulerAngles.z + rotOffset[2]));
transform.rotation = Quaternion.Slerp(transform.rotation, followRotation, followRotationSpeed * Time.fixedDeltaTime);
}
Comment