I don't really have a problem, but my code bothers me, because I know it could be done in a much better way.
I have an enum
of 4 directions: north west, north east, south east and south west. And I have a method that converts a vector to one of those directions. The method prefers North and East, so values of 0 would return those.
public enum Direction {
NORTH_WEST, NORTH_EAST, SOUTH_EAST, SOUTH_WEST;
public static Direction vectorToDirection(Vector2 vector) {
if (vector.y >= 0) {
if (vector.x >= 0) return NORTH_EAST;
else return NORTH_WEST;
} else {
if (vector.x >= 0) return SOUTH_EAST;
else return SOUTH_WEST;
}
}
}
If anyone can figure out a cleaner or more efficient method, I'd love to know!