I've been having some trouble with quaternions and rotations in Unity. I think I must be missing something in the documentation, but I can't seem to figure out what.
I want to rotate 2 unit Vector3s around an axis perpendicular to both of them. This should not change the magnitude of the vector. According to the documentation, quaternions should do the job. But no matter what I do, I don't get the results I want.
Here's an example of what I'm doing:
And this is the debug output from this code (slightly edited for clarity):
So as you can see, I start with unit vectors, get a perpendicular unit vector with the cross product as expected, but the confusion starts when I build the quaternion. I expected the quaternion to simply rotate the vectors and not change their magnitude, but that's not what happens. I get similar unexpected results no matter how I construct the quaternion.
The Quaternion reference page (http://docs.unity3d.com/Documentation/ScriptReference/Quaternion.html) is very clear and what I am doing here should work. I must be missing something simple, but I've been over it many times and I don't know what I should be doing.
Are negative angles not allowed? Do I also have to somehow specify a point to rotate around, as well as an axis? Is this actually the expected behaviour, and if so what should I be doing? I can't find an answer in the documentation.
Any help is appreciated.
Your vectors are still unit vectors. But the default display for Vector3 might be wrong.
Try using a formatted output:
And to check the magnitude of the vector use sqrMagnitude which is more correct:
answered Jul 12 '12 at 01:09 PM