Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created July 20, 2015 22:02
Show Gist options
  • Save unitycoder/1362b5fcb219ff0b3c0c to your computer and use it in GitHub Desktop.
Save unitycoder/1362b5fcb219ff0b3c0c to your computer and use it in GitHub Desktop.
Get 0-360 Angle Between 2D Lines
Vector3 from = p1-pMiddle;
Vector3 to = p2-pMiddle;
float angle = AngleBetween(from, to);
float AngleBetween(Vector3 vector1, Vector3 vector2)
{
var sin = vector1.x * vector2.y - vector2.x * vector1.y;
var cos = vector1.x * vector2.x + vector1.y * vector2.y;
float angle = Mathf.Atan2(sin, cos) * (180f / Mathf.PI);
if (angle<0) angle+=360;
return angle ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment