Qbasicnews.com

Full Version: Question about enemy ai
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
angle = ATAN ( (yP-yE) / (xP-xE) )

Where xP,yP is the player's pos.. and xE ,yE is the enemy's position.
Thanks! That code works.
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)]
Better use ATAN2 in FB. No checks needed.