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!

Kamikaze Enemy + Bomb (debris)

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 Inspector

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.

Updating the Firing Logic to drop bombs instead of Lasers. (We’ll get to the bombs briefly)

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!

Kamikaze Bomb

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!

Fancy Bomb

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.

Plus RigidBody 2D (gravity scale = 0) and Circle Collider 2D (Is Trigger)

Kamikaze Bomb Script

Giving our Bomb some logic. Nothing too crazy so here it goes:

Global Variables

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!

--

--

--

Audio Engineer turned Unity Game Dev. Will be combining both my skillsets when appropriate, and will be documenting my Unity Dev growth in these Medium Articles

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Swift development in a post-apocalyptic world

Creating a “Thermometer” Style Fundraising Counter with Bootstrap

Overall, I like this article. It's easy to read, no overloads per sections.

Live Streaming with RabbitMQ & SpringBoot Over Low or Intermittent Network

Send an SMS with Twilio and Golang

Building a Minimum Viable Product with Unity and C#

Rain And Snow Effect With Geometry Shaders In Unity

Day 23 of July LeetCode Challenge/

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Frank Warman

Frank Warman

Audio Engineer turned Unity Game Dev. Will be combining both my skillsets when appropriate, and will be documenting my Unity Dev growth in these Medium Articles

More from Medium

Unity new Input System : Progress Bar Charge (Part X)

Sphere Scene in Unity URP

How to Jump in Unity

WGTU #7: Atmosphere & narration — with Don’t Starve