Posts: 4
Threads: 2
Joined: Mar 2005
I'm working on a space shooter and I need to have the enemies have the ability to shoot at the player.
How can I make it so that an enemy ship is able to detect what angle to shoot at the player?
Posts: 6,419
Threads: 74
Joined: Mar 2002
angle = ATAN ( (yP-yE) / (xP-xE) )
Where xP,yP is the player's pos.. and xE ,yE is the enemy's position.
Posts: 4
Threads: 2
Joined: Mar 2005
Posts: 4,307
Threads: 63
Joined: May 2003
care to understand the math behind it?
Code:
o <- enemy (xe, ye)
|\
|A\
| \
| \
| \
|_ \
|_|____\
o <- you (xp, yp)
(yp - ye)
tanA = ---------
(xp - xe)
and so,
A = ATN[(yp - ye) / (xp - xe)]
Posts: 3,288
Threads: 167
Joined: Nov 2001
Better use ATAN2 in FB. No checks needed.