Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about enemy ai
#1
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?
Reply
#2
angle = ATAN ( (yP-yE) / (xP-xE) )

Where xP,yP is the player's pos.. and xE ,yE is the enemy's position.
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
Thanks! That code works.
Reply
#4
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)]
Reply
#5
Better use ATAN2 in FB. No checks needed.
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)