Need help figuring out the angle between 2 sprites...
![Post Post](./styles/prosilver/imageset/icon_post_target.gif)
What I'm basically trying to do is figure out the angle between a projectile and the player. I have the horizontal and vertical positions of both on screen, I just don't know the formula to use.
Then based on that I can figure out the horizontal and vertical speed of the projectile. So for example:
if the angle between them both is 0 degrees (player is DIRECTLY in front of, or behind, depending on your view) projectile, the hspeed will be 400000, vspeed will be zero. So it goes straight forward.
if the angle between them both is 90 degress (player is DIRECTLY aboveor below) projectile, the hspeed will be 0, vspeed will be 400000. So it goes straight down (if I want up I just make vspeed -400000).
If the angle is 45 degress the speed would be hspeed is 300000, vspeed is 300000 (these are negative for left, and up respectively).
Once I have the angle figured out I already have made the code for how to calculate the speed based on the angle, whether it's right or left, up or down etc. But I canNOT figure out how to get the game to calculate the angle of the player in reference to the projectile so it is thus aimed at him/her.
I've looked online and found some code snippets involving arctan, but those won't work here. Can anyone help me in creating this code to figure out what angle the player is in reference to the projectile?
Then based on that I can figure out the horizontal and vertical speed of the projectile. So for example:
if the angle between them both is 0 degrees (player is DIRECTLY in front of, or behind, depending on your view) projectile, the hspeed will be 400000, vspeed will be zero. So it goes straight forward.
if the angle between them both is 90 degress (player is DIRECTLY aboveor below) projectile, the hspeed will be 0, vspeed will be 400000. So it goes straight down (if I want up I just make vspeed -400000).
If the angle is 45 degress the speed would be hspeed is 300000, vspeed is 300000 (these are negative for left, and up respectively).
Once I have the angle figured out I already have made the code for how to calculate the speed based on the angle, whether it's right or left, up or down etc. But I canNOT figure out how to get the game to calculate the angle of the player in reference to the projectile so it is thus aimed at him/her.
I've looked online and found some code snippets involving arctan, but those won't work here. Can anyone help me in creating this code to figure out what angle the player is in reference to the projectile?