I'm new to unity and i'm already stuck on what seems to me as the simplest of functionality. I can't get the hang of rotations..
Let's say i have a
How would one go about to achieve this? I have been wrestling with Quaternions and Transforms, but to no avail..
Any help is most welcome!
There are several ways. Quaternions, though more complicated if you dig into their math, present the simpler alternative in terms of lines of code.
With quaternions, you can instantiate a Quaternion object using one of the static methods in the Quaternion class. You mention rotations about specific axes, so we can use the AngleAxis method to create a suitable quaternion. These are then multiplied onto the vector you wish to rotate. The result is the rotated vector. So the example you described above would be:
Note that the order must always be Quaternion*Vector, never Vector*Quaternion. I'm not a math wizard, but my guess is that this is related to the dimensionality of their underlying matrix representations. When you multiply matrices, the "connecting" dimensions must match, i.e. [1x4][4x4] is okay, but not [4x1][4x4].
There are plenty other ways to go about this, like EulerAngles, if you're more into that.
answered Mar 04 '11 at 11:41 AM