- Home /
Quaternion.RotateTowards to rotate beyond 360?
Hi,
This will probably sound noobish :) But why Quaternion.RotateTowards won't rotate beyond 360 degrees? Actually, even if I make the target 320 degrees, it will not rotate to 320 degrees but will go in the opposite direction to rotate to -40 degrees.
I understand what's happening but I'm curious if this is an issue with quaternion rotations in general or with RotateTowards?
function Update () {
var rotation : Quaternion;
rotation.eulerAngles = Vector3(0, 320, 0);
transform.rotation = Quaternion.RotateTowards(transform.rotation, rotation, 20*Time.deltaTime);
}
Yes, I know it's the same thing in the end, but what if I'd want my object to rotate five full circles? It would stop at the same rotation, of course, but the player would see it rotate five times over some period of time.
If you know the axis of rotation, there a few ways to solve this problem. Calculate the degrees per second at the start and use Transform.RotateAround() is one way.
Answer by markfm · Jan 15, 2013 at 08:50 PM
The only realistic way to do this would be to check if the rotational angle has reached 359 degrees. You need to understand that there is between -180 and 180. Therefore to make it go around 5 times you have two options.
Use the animator and animate it going round 5 times.
var speed = 10;
function Update {
if (transform.rotate.y => 90) { transform.Rotate(Vector3.up * Time.deltaTime * speed); } // do whatever when the planes move and repeat the above.
Hope this helps.Code above is untested.
Well, it would take too much space if I was going into details on what I was trying to achieve. In short, I wanted two airplanes to rotate 90degCV to their sides when passing one another and then completing the loop to 360 and do a full360 again when they pass each other. I did the first half (90degrees one), they do rotate relative to their distance, and I did write the remaining 2x360deg one, but when they pass each other, they just return to 0deg, going the CCV way, not continuing the started CV pirouette in CV direction. Anyway, I just achieved this with animation states. Thank you for commenting. I like doing these things through math, not animations, but it seems impossible because of this 360=0 convention.
Your answer
Follow this Question
Related Questions
Doing 2D only rotation using FromToRotation + RotateTowards 0 Answers
Convert Quaternion to Eulerangles 2 Answers
Quaternion.RotateTowards with 3 several rotation target 0 Answers
2D 360 degress platformer example needed 0 Answers
to rotate along z axis 1 Answer