Creating a boss battle, part 1

Now that my shooter as a wave system, it is only natural that I put a boss level at the end. Before I do that, I need a boss character. I found some art that worked as a boss and created an object out of it.

I gave it the usual rigidbody and box collider components and created a new script to handle the boss character’s behavior. Every boss needs a dramatic entrance, right? That’s what I’m doing first. I used a coroutine to slowly move the boss down into view, activate the boss, then have it begin the movement routine. Of course, the routine is called DramaticEntry. Why would it be anything else?


Once the boss is active, I want it to periodically move to random points on the screen. I’ll use another coroutine for that. First, it picks a random x-value between -6.5 and 6.5 and uses that to create a new Vector3 to serve as the target position. Then, in another while-loop, it’s using the Vector3.MoveTowards function to move the boss towards the target position. Once it’s there, it waits 3 seconds before picking a new location and moving again. This movement could be a bit more robust, and I might change things up later. But it works for now. (Side-note: are nested while-loops a bad practice in this scenario? It feels kinda dirty)


You know what this boss needs? A health bar. I’m going to implement one the same way I did the player lives UI element: by using an array of sprites and changing the rendered sprite depending on the health.

I created an empty object as a child of the boss and gave it a sprite renderer component. Then I made some variables in the boss script so I can reference the sprite renderer and change it via my code. When the boss takes damage, it decrements the health by 1 and chooses the appropriate sprite from the array to render on the screen.


Later on, I’ll be adding the functionality to begin the boss level after the final wave and end the game when the boss is destroyed.