|
Hello, 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.
(comments are locked)
|
|
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: Yes, Unity round the values to one decimal digit when you use the default ToString
Jul 12 '12 at 01:54 PM
Bunny83
I tried this and it works, problem solved. I was unaware that Unity handled printing vectors this way, although it makes sense now that I know. Thanks for your help.
Jul 13 '12 at 09:57 AM
perceivereality
Yes it is a bit disturbing at first. I think it should show more digits by default. Anyway, now I always use the formatted output.
Jul 13 '12 at 09:59 AM
Kryptos
(comments are locked)
|
