Fixed angle wrapping math.

When rotation was < 0, we were subtracting it from 360, which was
producing a number larger than 360. We should have been adding it to 360,
not subtracting.

Moved angle wrapping math to a separate function.
This commit is contained in:
Matt Low 2020-01-28 15:17:38 +04:00
parent 01c6a777cb
commit b9e63dea26

View File

@ -10,13 +10,15 @@ public final class Utils {
private static final Vector2 tmp = new Vector2();
public static float rotate(float rotation, float degrees) {
rotation += degrees;
if (rotation < 0) {
rotation = 360 - rotation;
} else if (rotation > 360) {
rotation -= 360;
return wrapAngle(rotation + degrees);
}
return rotation;
public static float wrapAngle(float degrees) {
if (degrees < 0)
return degrees + 360;
else if (degrees > 360)
return degrees - 360;
return degrees;
}
public static Vector2 setUnitVectorAngle(Vector2 vector, float degrees) {