- Home /
Quaternion rotation infinite?
Hey i got this piece of code and it makes a door rotate, so for example the start rotation of the door is 0 deg, and openangle is set to 90 deg, when i hit run, the door slowly rotates and the degrees go from 0 to 1 to 2 up until 90, but does it actually every reach this value, or is it going to 89,99999 and is unity just rounding the numbers?
Quaternion target = Quaternion.AngleAxis (OpenAngle, Vector3.down); //Creates a rotation which rotates OpenAngle degrees around y-axis
hinge.transform.rotation = Quaternion.Slerp (hinge.transform.rotation, target, Time.deltaTime * speed);
Answer by Xarbrough · Apr 05, 2015 at 06:21 AM
You're assumption is correct. From every rotation value you move a tiny bit closer to 90, but it's always getting a smaller fraction the closer you move to 90 and it will never in fact reach it. The editor just rounds off numbers and at some point your float will just not hold enough digits. See this for a more detailed explanation: http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/tips-tricks-4
If you really want to use the Lerp function in a smoothdamping way, you can just check if the difference of your current rotation and the target is smaller than a a very small threshhold. But watch the video for more suggestions.
hey, I got it to work by using a threshold like you suggested to, thank you :)
Your answer
Follow this Question
Related Questions
Quaternion + many collision meshes = intense lag? 0 Answers
Quaternions incorrect? 2 Answers
How to find a rotation of a child object 0 Answers
Simple Rotation 1 Answer
i have rotated an gameobject but the axis of the object did not change 2 Answers