# Vector3.Angle noob question

who can explain why:

``````Debug.Log (Vector3.Angle(Vector3.up,new Vector3(-1,-1,0)));

Debug.Log (Vector3.Angle(Vector3.up,new Vector3(1,-1,0)));
``````

both return same value 135, instead of 135 and 235.
(The same with Vector2)
and how to get around that?

Say you are standing up and looking ahead.

(-1,-1,0) is LEFT and DOWN … at a 45 degree angle. Ok?

imagine a “tunnel” going in to the ground, to your LEFT, at a 45 degree angle.

(1,-1,0) is RIGHT and DOWN … also at a 45 degree angle. Ok?

imagine a “tunnel” going in to the ground, to your RIGHT, at a 45 degree angle.

In fact! from BOTH those places, (from both the tunnels) to get UPRIGHT … up to the sky … is 135 degrees!

it makes no difference what “compass direction” the tunnel is pointing.

Can you see this OK now ?

Next: you ask about “235”. I’m assuming you want it to go “all the way around” is that correct? “Vector3.Angle” won’t help you with that because of course it goes the 'shortest way".

What you are talking about is actually a very difficult problem in game programming! But I suggest the simplest solution for you is, very simply in your example 360 minus 135 is 235. Just check if you are “on the right” and then you know you have to say 360 minus the number. You see what I mean?

if that doesn’t work for you (or anyone reading in the future) your next step is to learn about Quaternions, and beyond that a lot of trigonometry and beyond that just more logic like “if I am down and to the right, I need to do THIS calculation …” Its pretty annoying at any level!

I found this while searching for the solution to this problem…

http://www.gamedev.net/topic/542870-determine-which-side-of-a-line-a-point-is/

This solved my issue, the final code looking something like…

``````        Vector3 difference = heading - p.ShipInfo.Position;
Vector3 perp = new Vector3(-difference.y, 0, difference.z);
float d = Vector3.Dot(hit.point - p.ShipInfo.Position, perp);
Debug.Log(Mathf.Sign(d));