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


Unity has a built-in function for this:

public static float DeltaAngle(float current, float target);


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.