I have an image that represents a character. By default, the character depicted in the image is standing and heading right. ( -> )
Then, inside the "game" the character has a velocity vector (x,y).
So, given this velocity vector I'm calculating an angle in the following way:
float radians = atan2(x_vel, y_vel);
So far, so good. A first problem was that when the velocity represents an angle of (180 CCW) the image gets upside-down. So what I did was to check if the x velocity was smaller than zero, and if it was, then I'd flip the image horizontally.
But now I can't figure out how to apply the rotation. I need a way to adjust the rotation that comes from atan2 depending on whether the image is heading left or right.
coord (0,1) π/2 │ │ <-heading left │ heading right -> │ │ │ │ coord (-1,0) π ────────────────┼─────────────── 0 or 2π coord (1,0) │ │ │ │ │ │ 3/4π coord (0,-1)
Thanks in advance.