I have a flying object and I want to point it in the direction it’s heading. What I have is the object’s current x and y velocity and the ability to rotate the image. So what I need is a function that takes the x and y velocity and gives me the degrees I need to rotate by. This is the function I have so far:
private float getRotation(float x, float y)
{
if (x == 0 && y > 0)
return 90;
else if (x == 0 && y < 0)
return 270;
else if (x > 0 && y == 0)
return 0;
else if (x < 0 && y == 0)
return 180;
else if (x == 0 && y == 0)
return 0;
else
return ????;
}
What I have is so far correct, except where the ???? is, the most important part. Anyone know how to make this work?
This might be more of a math problem, but it involves programming, so if this is on the wrong forum I apologize.
Math.atan2()