- Home /
Follow rotation on Y axis ONLY clockwise/counterclockwise.
The code I'm using now follows target position and lerps to target rotation. But when it can't catch up, it changes direction since it becomes shorter way to the target. How can I follow rotation on Y axis ONLY clockwise/counterclockwise? I've been trying to find an answer for a long time. Please help.
void FixedUpdate()
{
transform.position = new Vector3(follow.position.x, follow.position.y, follow.position.z);
Quaternion followRotation = Quaternion.Euler(new Vector3(followRot.eulerAngles.x, followRot.eulerAngles.y, followRot.eulerAngles.z));
transform.rotation = Quaternion.Slerp(transform.rotation, followRotation, followRotationSpeed * Time.fixedDeltaTime);
}
Answer by Barkine94 · Feb 08 at 08:44 PM
Mathematical lerp functions are not best way to lerp angles. Consider using lerpangle for each individual rotation (x, y and z)
Oh sorry that I misunderstood your question. You need to use transform.rotate with constant or variable speed (it needs to always be positive or negative for the same direction). You can check the difference between euler angles with vector3.distance or you can just check the difference between the desired axis. If it is more than a delta value you can just keep rotating. Hope this helps.
Thanks! That definitely helps. Make this an answer so I can accept it.
Your answer
Follow this Question
Related Questions
Rotate an object so its up vector matches a sphere 1 Answer
How to combine multiple rotations at once? 0 Answers
few question about quaternion slerp 3 Answers
Directional booster 1 Answer
What is the rotation equivalent of InverseTransformPoint? 3 Answers