How do I find the angle required to point to another object?
Posted
by
Ginamin
on Game Development
See other posts from Game Development
or by Ginamin
Published on 2012-04-04T14:51:28Z
Indexed on
2012/04/04
17:42 UTC
Read the original article
Hit count: 250
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?
© Game Development or respective owner