- Home /
How to always rotate clockwise
Hello, I have an object that I need to rotate clockwise only around Z axis until it matches a specific angle that will be decided randomly at run time. If I use any of Quaternion static functions they all choose the shortest rotation and sometimes it rotates anti-clockwise. Any ideas?
Edit: I forgot to mention that the rotation shouldn't be instantaneous, it will be Lerp like, the problem with Quaternion static functions is that they always rotate in the shortest direction and I need to always rotate in clockwise direction.
Answer by korbul · May 04, 2016 at 04:56 PM
Hello, can you post the code you are using now?
Have you tried
 Quaternion rotation = Quaternion.Euler(0, 0, myRotationInDegrees);
edit: for lerping a quaternion not trough the shortest route, i recommend something custom made
 public class QuaternionLerp : MonoBehaviour {
     public float zAngleTarget;
     public float secondsToLerp;
     float t;
     // Use this for initialization
     void Start () {
         t = 0;
     }
     
     // Update is called once per frame
     void Update () {
         t += Time.deltaTime / secondsToLerp;
         transform.rotation = Quaternion.Euler(0, 0, Mathf.Lerp(0,zAngleTarget, t));
     }
 }
Thanks for responding, the problem with Quaternion.Euler(0, 0, myRotationInDegrees); is that it will make instantaneous rotation. what I need is something like Quaternion.Lerp but I get to choose the direction of rotation
Your answer
 
 
             Follow this Question
Related Questions
Rotating a model with increments 1 Answer
How i can equal 2 Tranform Rotations? 1 Answer
Flip over an object (smooth transition) 3 Answers
Particle System Instantiate's With Original Rotation - C# 1 Answer
Wrong rotation while moving 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                