Get the difference between rotations

I’m working on a system where your character turns and depending on what rotation from an array is the closest to the current character’s rotation, it will set the rotation to it.

However I’m struggling with the rotators and the math behind it. I can’t find a way to get this working that takes into account the change from 0 to 360, or 180 to -180.

Is there a way to find the difference between rotations considering the change from 360 to 0 degrees?

1 Like

Hello ,

Have you considered converting the values into Radians and doing the math that way? This way everything will be measured in fractions and multiples of Pi.

If you need to compare a rotation of 1 and 359 degrees, where the difference is 2, you would need to subtract 1 from 359, which would give you 358. This is obviously not correct unless you have a restriction on passing 360 and resetting. In this case, you can have a condition to check the difference and see if it is over 180. If it is, subtract 360 from it and get the absolute value of the new difference. This will result in 2. This should all be converted to Radians if you want pin-point accuracy though.

Hope this helps!

1 Like

Hey, thanks for the answer! I’ll do the research into Radians, this is pretty much the answer I was looking for.