Tracking missile

Hi, I have a question about making missiles track the player. In my game the player controls a flying machine which is viewed from directly above. I’ve created a camera system that follows the player’s rotation and moves the world around them. Basically they can turn any direction and the whole world will rotate so the player is always facing forwards on the screen. 

The problem I have is trying to include a missile tracking system. I want missiles to be able to chase the player.

The following code has worked fine in other games(without a rotating camera):

[lua]

–>> Calculate angle between player and missile 

local angle = math.atan2(player.yPos - missile.yPos , player.xPos - missile.xPos)

                

local trackX = (math.cos (angle) * trackingSpeed)

local trackY = (math.sin (angle) * trackingSpeed)

                

missile.x = missile.x + trackX

missile.y = missile.y + trackY

[/lua]

If the player moves forward in their initial direction then everything behaves as expected, but if they turn around 180 degrees then the missiles will actually reverse and run away from the player. It is something to do with the whole camera group being flipped upside down, but I just can’t wrap my head around it.

I would really appreciate it if anyone could share their thoughts on this or even recommend a better tracking algorithm. Thanks for reading.

Any ideas?

Hi @arlenraisbeck,

Please see this 3rd-party tutorial, which may be what you need:

http://jyjsophia.blogspot.kr/2013/09/about-enemy-tracking-missile-homing.html?m=1

Brent

Any ideas?

Hi @arlenraisbeck,

Please see this 3rd-party tutorial, which may be what you need:

http://jyjsophia.blogspot.kr/2013/09/about-enemy-tracking-missile-homing.html?m=1

Brent