- Home /
The question is answered, right answer was accepted
RotateTowards, Quaternion conditional, do Quaternions have 2 values?
Sorry for yet another quaternion question. basically i want to know if there are 2 quaternion values that are the same, like an opposite. I am using RotateTowards and then an if to check whether it has finished rotating. The problem is that printing the angle that its supposed to end at is different than my actual angle, even though rotateTowards seems to have finished. here are the prints that i get: Expected Angle : (0.0,0.9,0.0,-0.4) After RotateTowards : (0.0,-0.9,0.0,0.4) the If statement is never getting true since some of the values are inverted but they still seem to be correct. how can i make this work? or is there a better way to check for when Rotate Towards is finished? here is some of my code:
weaponBarrel.transform.rotation = Quaternion.RotateTowards(weaponBarrel.transform.rotation,barrelRot,barrelRotateSpeed*Time.deltaTime);
if(weaponBarrel.transform.rotation==barrelRot){
fire=true;
}
see how barrelRot is in the if statement and the rotateTowards statement...
Answer by Owen-Reynolds · Jun 21, 2012 at 10:38 PM
Yes. Quaternions are a "double cover," which means there are two ways to write each value.
To check close enough, on a rotation, I usually check Quaternion.Angle(current, target)<small
, which is probably very inefficient.
Supposedly (never tried this,) even though dot product isn't the same for Quats, you can check if Abs(Quaternion.Dot(A,B))
is close to 1, you have the same angle. (In other words, dot product is 1, or -1 since you got the "other" version of the angle.)
hey Owen, thanks for your answers. I am using the Quaternion.Angle
Follow this Question
Related Questions
Quaternion.RotateTowards() immediately snaps to target rotation 1 Answer
How to rotate towards the mouse on one axis while snapping 0 Answers
Object rotate to target in 2D? Not working properly. 0 Answers
Doing 2D only rotation using FromToRotation + RotateTowards 0 Answers
Quaternion.RotateTowards with 3 several rotation target 0 Answers