Aggressive Enemy Type

Jason Schneider
2 min readJan 15, 2022

Since our Enemies are not aggressive enough, I think we should add the kamikaze ability to some of them. For this, we will of course need to add code to our Enemy script:

As can be seen above, we have introduced two new variables, since our code does not know what they are we will have to add them.

Then, we will need to add the following to the Update() method:

Saving the script, jumping back into Unity, pressing play and then pause. Then setting the spawned Enemies, Enemy Ram Active to true and pressing pause again, will give:

Awesome, we are half way there, now we need to have the Enemy travel in the direction it is facing. To accomplish this we will need to create another method:

Now we can use this new variable by putting the following into the EnemyMovement() method:

Saving the script, jumping back into Unity, pressing play and then pause. Then setting the spawned Enemies, Enemy Ram Active to true and pressing pause again, will give:

Fantastic, now we just need to clean up what happens when the Enemy goes off the screen. I will leave that to you.

--

--