Greetings,
I've been trying for days to figure out how to calculate where I need to turn in order to face my waypoint. I am aware that there's been several threads created asking for this - in which solutions has been posted. However, nothing is giving me equitable results.
So the question is: How do I calculate what my player rotation has to be (out of PI*2) in order to face my waypoint which is at: X:55.24, Y:66.89
I get my player rotation from the wow API - GetPlayerFacing(). The coordinates I'm working with are formatted as such:
55.71, 67.51
This is one of the functions I've tried (Which has returned utterly wrong angles) It's however returning something... But I found no pattern in the results:
C#
Code:
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show(GetFacingAngle().ToString());
}
public static float GetFacingAngle()
{
float angle = (float)Math.Atan2(target_y - player_y, target_x - player_x);
if (angle < 0.0f)
{
angle = angle + (float)Math.PI * 2.0f;
}
else if (angle > (float)Math.PI * 2)
{
angle = angle - (float)Math.PI * 2.0f;
}
return angle;
}
What am I doing wrong?