Day 25: Adding Extras —Different Enemy Types

Gerald Clark
4 min readMay 27, 2021

I’ve added a few different types of enemies:

  1. A Follower — follows you until it collides dealing damage. If your Y axis > the enemy’s is flies down.
  2. An Avoider — avoids your regular laser, only hit by homing missile.
  3. A Laser Beam enemy — A slower enemy that sweeps across the board firing a laser that is nearly unavoidable.
  4. An Enemy that fires when it gets behind you
  5. A Boss Enemy.

The follower was fairly simple to create since the homing missile uses similar features.

This one should be fairly simple to figure out. Lets move on.

This enemy fires a laser when its y position < yours.

I’ve set this one up to instantiate a laser when the y position is less than the player’s. This enemy cannot be collided with.

The Laser beam enemy was set up by setting waypoints for it to fly to and from. This was accomplished with this code:

I used Mathf.Clamp in case I wanted to have this one move up and down as well, but eventually kept it to only move horizontally. Then I used MoveTowards(), (my favorite) and set the destination to the waypoints.

I used a coroutine for the laser beam to randomly fire and stay “active” for 5 seconds at a time.

I also used a coroutine for the “hit marker”. When a laser collides with this enemy it turns red for a split second. This was accomplished using:

We just change the material color to red and then back to white. EASY

This enemy also has hit points. So we say hitPoints--; when a laser collides with this enemy and set the hitPoints to 3 initially.

The avoider enemy is a very simple implementation. I just used an edge collider to detect the laser and then I have the enemy transform change to transform.position.x + 2.

The horizontal line in front of it is the edge collider. It also has its own box collider so the homing missile can still collide with it.

this will never be hit by a laser moving up at it. The homing missile still damages this enemy and rewards the player with 100 points!

Now for the boss. I have it set up similarly to the Laser beam enemy and want to add more functionality to it, but I may save it for when I add more levels.

Here is our Boss Enemy.

It takes 15 shots to destroy this enemy, and then the UI displays “YOU SAVED THE GALAXY!!!” It fires 8 lasers at a time from the “teeth” on the wings. OVERPOWERED MUCH!?!?

Destroyed Coroutine:

The boss explodes in several places before the game object is destroyed. This is accomplished with the following code.

Its literally just instantiated explosion prefabs in specified places. I’ve made a few empty game objects and parented the boss enemy. When it runs out of hitpoints this coroutine happens. Disregard the Wave update in this gif. When the enemy dies the wave updates, but when it actually spawns it is technically wave 4. Once the array goes past the array bounds (4) the You Win screen happens.

--

--

Gerald Clark

Father Game Developer Music Composer Sound Designer