How do I find the angle required to point to another object?
- by Ginamin
I am making an air combat game, where you can fly a ship in a 3D space. There is an opponent that flies around as well. When the opponent is not on screen, I want to display an arrow pointing in the direction the user should turn, as such:
So, I took the camera location and the oppenent location and did this:
double newDirection =
atan2(activeCamera.location.y-ship_wrap.location.y,
activeCamera.location.x-ship_wrap.location.x);
After which, I get the position on the circumferance of a circle which surrounds my crosshairs, like such:
trackingArrow.position = point((60*sin(angle)+240),60*cos(angle)+160);
It all works fine, except it's the wrong angle! I assume my calculation for the new direction is incorrect. Can anyone help?