|
Hey guys, 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!
(comments are locked)
|
|
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. Thank you very much! I've been trying to get this to work for a week, searching the forums like crazy. But this is very clear example!
Mar 04 '11 at 01:47 PM
PitchBlackCat
wow, I never knew you could multiply Quaternions by Vectors, I guess this is some of the underlying reasoning behind Quaternions being called Euler parameters? [edit:] and infinite respect btw to this answer.
Aug 25 '12 at 01:10 PM
Matt Downey
(comments are locked)
|
