Hello!
I wonder if there is a simple way of finding the angle between two Directions.
I have the forward direction of a gameobject, then I have the angle to the target, and I want to find the anglebetween these two.
I know there is a Vector3.Angle method, but this only gives me an absolute angle difference.
I basically need to use this for banking a ship, so when it turns towards a new waypoint, I will rotate it a little around the z axis.
Thanks a bunch!
Kjetil
Assuming this is essentially a 2-d problem and you want to find the signed angle with respect to the world ‘up’ vector, you can compute the signed angle by multiplying the unsigned angle (computed using Vector3.Angle()) by the sign of the dot product of the up vector and the cross product of the two input vectors, e.g. (pseudocode):
signed_angle =
unsigned_angle * sign(dot(cross(direction_1, direction_2), world_up));
You might need to swap the arguments to the cross product function to get the correct results.
First, you need to think 2d on the plane of the vehicle you are using. So all those Vector3 things, throw them out the window, you only need the X and Z from them.
You would need to figure the localized angle of the vehicle in relation to the point that you want to go to. So you would use the InverseTransformPoint to get that against the forward direction (Vector2(0,1)). This gives you the absolute angle between the two points.
Next, you want to use a Vector2.Dot to check the right direction (Vector2(1,0)). If that vector is less than zero, you need to negate the angle.
Lastly, you would want to use a maxBank variable and chart it against the yAngle/180. This gives you the Z angle that you want to use.
var maxBank=30.0;
// 2d angle ( local )
var targetPoint=transform.InverseTransformPoint(GameObject.Find("Target").transform.position);
//targetPoint.Normalize();
var v1=Vector2(targetPoint.x, targetPoint.z);
var v2=Vector2(0, 1);
var v3=Vector2(1, 0);
var yAngle=Vector2.Angle(v2, v1);
yAngle=Vector2.Dot(v3, v1) >0 ? yAngle: -yAngle;
print(yAngle / 180 * maxBank);
Doesn’t Vector3.Angle do this all in one simple command? 
Vector3.Angle() returns the unsigned angle. The OP wants the signed angle. (Or so it appears.)
Thank you so much guys for all the feedback!
I’ll try this out and see if I get it working 
And yes, I tried Vector3.Angle, but didn’t help me as much as I needed to know if it was a positive or a negative number.
The Vector3.Angle gives the raw angle between the point where you are going and the point where you want to be, regardless of your UP vector. converting to 2d retains the up vector.