Hi guys, I am trying to get a continuous angle between two vector3s, using Vector3.Angle, the angle seems fine until the object hits 180 degrees, but then the angle starts going down from 180. I’ve tried the code from how to calculate the angle between two vectors? - Questions & Answers - Unity Discussions (below) which should return an angle between -180 and 180, however the angle returned is always a negative one. Ive also tried similar code form other threads but still not working for me.
var waypoint1 : Transform;
var waypoint2 : Transform;
var force : float = 4;
function Update(){
if(Input.GetKey("w")){
transform.RotateAround(waypoint1.position, Vector3.forward, force);
}
var referenceForward = Vector3.right;
var referenceRight= Vector3.Cross(Vector3.up, referenceForward);
var newDirection = waypoint1.position - waypoint2.position;
var angle = Vector3.Angle(newDirection, referenceForward);
var sign = (Vector3.Dot(newDirection, referenceRight) > 0.0f) ? 1.0f: -1.0f;
var finalAngle = sign * angle;
Debug.Log(finalAngle);
}