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:
The arrow will be on the HUD. It will not actually turn to the opponent. I want it to indicate which direction a user should turn to see the enemy ship. This arrow will circle around the cross-hairs (radius 60 pixels).
So, I took the camera location and the opponent 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?