This sounds simple but I haven’t found a way to do it.
I know how to get just the magnitude of a Vector3. How can I read just the direction (x, y, z angles or a quaternion)?
This sounds simple but I haven’t found a way to do it.
I know how to get just the magnitude of a Vector3. How can I read just the direction (x, y, z angles or a quaternion)?
Your best bet would probably be Quaternion.LookRotation
However, there is no unique answer - if you have a vector, then you can put something that looks along this vector (that’s what LookRotation does). However, that thing might freely roll around the vector, while still looking along it (that’s why LookRotation also needs a “up” vector to align).
[EDIT: Just saw Aras’s post…]
Perhaps a normalized vector is what you are looking for?
directionVector = myVector.normalized;
Leaves you with a vector with a magnitude of 1, so in other words, a direction vector.
Hope that is what you were asking,
-Jeremy
OK, thanks. Z is irrelevant so I can just use world up.
By the way, is Vector3.AngleBetween intentionally missing from the 1.5 manual? I tried using just Angle but it doesn’t produce the same results as AngleBetween. So I’m still using AngleBetween and it still works fine in 1.5.
AngleBetween returns radians. Angle returns degrees. Nobody wants to deal with radians, so AngleBetween is undocumented (but it’s still there so that old code still works)
I see. Sometimes you need radians though!
Thanks for clearing that up.
Multiply your degrees by Mathf.Deg2Rad;
-Jeremy
Yes, I use Mathf to go back and forth at will.
So how do you get the direction from one vector to another?
(myVector1 - myVector2).normalized ? I never did vector math so I have to get everything from the forums and examples ;).
Yes. Tough if you want it from vector1 to vector2, you do (vector2-vector1).normalized
That is, end point minus start point, then normalize.