How can I find the angle between two angles that go from -180 to 180 degrees?
I would like to do :
if (angleDiff > 90)
{
// The angle is bigger than 90 degrees...
}
I tried subtracting them but that doesn't seem to work. Thank you
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityHow can I find the angle between two angles that go from -180 to 180 degrees?
I would like to do :
if (angleDiff > 90)
{
// The angle is bigger than 90 degrees...
}
I tried subtracting them but that doesn't seem to work. Thank you
Unity has a built-in function for this:
public static float DeltaAngle(float current, float target);
Description
Calculates the shortest difference between two given angles given in degrees.
So you can write...
if ( Mathf.Abs(Mathf.DeltaAngle(angleA, angleB)) > 90f ) { ... }
Don't forget to search for past answers and read the documentation when you have questions about common tasks like this. It's almost guaranteed you're not the first one to try to solve this problem.