New Enemy — Kamikaze Enemy
What’s scarier than an Enemy hurdling towards you that shoots lasers? How about an Enemy that moves towards you, and drops pieces of debris that explode?! AND THEY’RE ON FIRE!
That’s pretty much what my new Kamikaze Enemy is. They move a little slower, but move towards you, so they don’t fall in a straight line. Slightly more challenging, which is always good!
Creating the Kamikaze Enemy
For this Enemy, I’m simple reusing the previous Enemy sprite and tinting it slightly red, but using a couple frames of the Enemy Explosion VFX to give it it’s flashing body flame VFX. Then adding on the Player Damage Indicator VFX to make them seem more damaged.
Pretty good reasons to kamikaze the Player, no?
And of course adding the RigidBody 2D (gravity scale to 0), and Box Collider 2D (Is Trigger selected).
Kamikaze Enemy Script
This script is essentially the same as the regular Enemy script except it drops Bombs instead of Lasers, we’ve updated it’s Movement function, and it has some code to always face the Player.
And the updated Movement():
The hardest thing to wrap my head around is Quaternions and Euler angles for rotation. They get extremely complex and I bet you could write hundreds of articles explaining them.
I won’t be doing that in this article, but maybe at a later time!
For now, trust the code, because it does work!
Now for another Projectile! This time, the new Bomb will damage the Player if it collides with them, but also will explode after a set amount of time which will also damage the Player if they get caught in it’s wake!
The bomb uses the base sprite of the Asteroid as the Parent, and has 4 Player Thruster VFX Sprites hiding underneath as children! Then I’ve simply animated the Player Thrusters (while using my Asteroid parent to hold the Animator Controller) to flash by making them darker and looping the Animation.
Kamikaze Bomb Script
Giving our Bomb some logic. Nothing too crazy so here it goes:
During Start() we null check the Player and start our Explosion() function to detonate!
Explosion() holds our Coroutine which holds our BombExplosion(). The _bombExplosionVFX is just a regular explosion, scaled down and tinted red to alert the Player that it’s super dangerous!
Our movement for the bomb I kept in Update() because its the only thing there, but you can definitely move it to it’s own function!
And finally, our logic for interacting with Player:
Bomb Explosion Script
I also created this script to attach to the BombExplosionVFX , adding to the danger of the Bombs. If a Player gets caught up in the explosion, they will get damaged:
So with all of that, we have a new Enemy and also a new Projectile! Don’t forget to link all your References in the Inspector and be sure to Prefab your new Enemy and place them in your Spawn Manager array!
In the next article we’ll be giving Shields to random Enemies!