Unity2D Devlog 21 — Never Miss Again!

Claudio Grassi
3 min readJul 12, 2021

Lately, I’ve been on a rollercoaster ride of balancing and counterbalancing game mechanics. It has been a blast. Now that enemies can dodge the Player’s bullets, maybe it’s best to include a weapon they can’t avoid.

Objective:

Create a new weapon type for the Player: The Homing Missile.

How I went about it:

As with every other power-up, I began by creating some art. If you see this bad boy coming towards you, you had better smash the acceleration pedal!

I am now ready to begin coding the behavior for this new weapon.

A homing missile has to perform a series of tasks after being fired. The first of these tasks is to find all available targets in the area. To accomplish this step, I wrote the following code.

The method first looks for all Enemy Components in the scene. After looping through each element, it returns the closest enemy in the Array.

Once a target has been found, the missile must establish a path to travel. This task involves a couple of steps. I want the Missile to travel forward for a short while before it locks onto its target. Then, I can establish the direction from the Missile’s position towards the closest enemy. Finally, the missile will have to rotate towards its target and travel to it until they collide.

After firing the rocket, it will wait 0.5 seconds before finding a target and activating.

Now that the rocket has a target, I can determine its direction and begin moving towards it. To do this, I have the following method.

--

--

Claudio Grassi

Experienced digital artist, Unity game developer & coder with a knack for problem solving and a passion for video games.