 menu

1. ## Facing a waypoint

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?  Reply With Quote

2. Works for me.

Code:
```var delta = target.Position - player.Position;
var angle = Math.Atan2(delta.Y, delta.X);
angle += Math.PI * 2;
angle %= Math.PI * 2;```  Reply With Quote

3. It really does not want to work for me. I for example get 3.45678 when it should return 5.16789. The results are always inconsistent.

-Edit-

With this placement of coordinates, it works.
I'll leave the solution here:

Code:
```var target_x = Navigation.loadedXcoord;

var atan2X = (player_x - target_x);
var atan2Y = (player_y - target_y);

double angle = (float)Math.Atan2(atan2X, atan2Y);

angle += Math.PI * 2;
angle %= Math.PI * 2;

return (float)angle;```
Thank you Jadd, for pushing me in the right direction.  Reply With Quote