- Home /
Rotation to direction vector?
How can I get a normalized direction vector from an objects rotation?
How can I do this without using a transform component? Like, using a Quaternion or a Vector3 itself?
Answer by aldonaletto · May 12, 2012 at 09:17 AM
As @jimmyjjeeter suggested, you can use transform.forward (as well as transform.up for the up direction, transform.right for right, -transform.right for left etc.).
If you have a quaternion but not the transform, you can rotate a vector like this:
var rotatedVector = someQuaternion * Vector3.forward;
NOTE: Order matters in the quaternion world: it must always be quaternion x vector (vector x quaternion produces an error).
Thanks for answering with the math behind the function @aldonaletto
Answer by JimmyJJeeter · May 12, 2012 at 09:10 AM
Isn't that just transform.forward?
@JimmyJJeeter ugh yes, you are right, can't believe I forgot about that.
Answer by Nition · Aug 09, 2017 at 12:45 AM
I always end up here when I've forgotten how to convert a rotation to a direction vector, so here's a complete answer for anyone else ending up here or for me 6 months from now.
For a Quaternion rotation:
Vector3 forwardVector = yourQuaternionRotation * Vector3.forward
And for a Vector3 rotation:
Vector3 forwardVector = Quaternion.Euler(yourVector3Rotation) * Vector3.forward
lol, just came looking for how to do this again. I see it's been just over six months...
Can't believe I'm here again almost right on another six months. I'm going to write this info down locally now so this may be my last visit.
I generally find that it's easier for me to remember something if I really understand why it works. I'd recommend doing that here. $$anonymous$$eywords are "rotation matrix" and "transformation matrix" (and, of course, "quaternion")
Very helpful, thank you :) I totally get how you need to re-remember things sometimes. Fantastic you did this haha
Your answer
