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:
parent
01c6a777cb
commit
b9e63dea26
@ -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 rotation;
|
||||
return wrapAngle(rotation + degrees);
|
||||
}
|
||||
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user