Creating Heat Seeking Missiles

When you play a game, combat can become repetitive unless there are aspects of it that feel diverse or unexpected. By incorporating different enemies that utilize different moves, weapons, and animations you can create all sorts of scenarios to challenge and entice your players.

For my Space Shooter game, I am incorporating an enemy that will fly in from the side stop, stop at a random location on the X-axis, fire between 2–4 heat-seeking missiles, and then fly off.

To make these missiles follow the player I will have to create a reference to the player object and get its transform. Then it’s mostly a matter of getting the missile object that this script is attached to rotate and follow the player.

Attach the script above to your missile object and make sure your player is tagged as “Player”. The missile will now follow the player and point in the player’s direction so long as it is on a 2D plane. Now it’s just a matter of setting up how you want your missiles instantiated. If you look at the GIF below you will see my enemy AI in all its glory!

Hi, my name is Adam Reed and I am a software engineer specializing in Unity and C# development. Feel free to scroll through and check out some of my work!