# Getting the direction of a vector?

Discussion in 'Scripting' started by Morgan, Jun 23, 2006.

Not open for further replies.
1. ### Morgan

Joined:
May 21, 2006
Posts:
1,223
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)?

### Unity Technologies

Joined:
Nov 7, 2005
Posts:
4,770
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).

3. ### jeremyace

Joined:
Oct 12, 2005
Posts:
1,661
[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

TaylorVD and Nugget5 like this.
4. ### Morgan

Joined:
May 21, 2006
Posts:
1,223
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.

### Unity Technologies

Joined:
Nov 7, 2005
Posts:
4,770
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)

6. ### Morgan

Joined:
May 21, 2006
Posts:
1,223
I see. Sometimes you need radians though!

Thanks for clearing that up.

Joined:
Oct 12, 2005
Posts:
1,661

-Jeremy

8. ### Morgan

Joined:
May 21, 2006
Posts:
1,223
Yes, I use Mathf to go back and forth at will.

9. ### Marble

Joined:
Aug 29, 2005
Posts:
1,266
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 .

### Unity Technologies

Joined:
Nov 7, 2005
Posts:
4,770
Yes. Tough if you want it from vector1 to vector2, you do
Code (csharp):
1. (vector2-vector1).normalized
That is, end point minus start point, then normalize.

vegn and Ash-Blue like this.