I'm trying to compare two rotations.
I'm checking to see if they are equal like this
Here's an example of the Debug.Log of two that were not equal according to the if statement. But look at the output...
prevrot=(0.0, 0.0, 0.0, 1.0) rot=(0.0, 0.0, 0.0, 1.0)
Why doesn't the Debug.Log output match the if statement?
Answer by ScroodgeM
Jul 22, 2012 at 06:32 AM
internally quaternion stored as 4 floats, so two quaternions can be different but both logs as (0,0,0,1) due to precision of float.
use this to compare two rotations by angle between them - for example if angle is lower then some threshold then these quaternions are same
Thanks for the clear explanation and solutions.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
To help users post good questions and use the site effectively we have posted a user guide. Please check it out.
Answers and Comments
5 People are following this question.
preventing errors by calling Debug.Log on a property
Quaternion Error, what does it mean?
How is the rotation of a Transform converted into a Vector3 in the inspector ?
Rotations Not Matching with What is in Inspector
Question Regarding Direction Moving