Creating a Boss Enemy — Part 1, Waypoint Movement
Well, the Galaxy Shooter game is almost ready to be released into the world, but it’s missing one final touch! A Big Bad Boss Enemy to test our Player’s skills!
In the next few articles we’ll be creating a Boss Enemy that has a few intricate parts that all work together. The Boss will have a new movement system, waypoints, which we’ll cover in this article.
The Boss Aesthetic
Obviously, the Boss has to stand out and feel pretty gargantuan. So I’ve added a few features and a couple parts to make it feel that way.
It’s not a super complicated mish-mash, I’m still just reusing assets, haha. The base is a regular Enemy sprite, scaled up of course, and I have two Player ship sprites behind the base to give the Boss a kind-of crown aesthetic.
Then I tinted them a shade of blue, because then I surround them with an Asteroid Belt of Freeze Asteroids (that will eventually revolve around the Boss and have a small enlarging-animation).
The Hierarchy of my Boss:
Then I added the Rigidbody 2D (gravity scale = 0), Circle Collider 2D (Is Trigger, around the Boss only; not the Asteroid Belt).
And created and attached a new EnemyBoss script to add all of our logic.
Creating a Waypoint system
Since I wanted the Boss to feel special, rather than just let fall down screen and reappear at the top, I created a basic waypoint system for them to follow.
It consists of 3 waypoints that the Boss chooses randomly when it reaches it’s destination.
So let’s jump inside the EnemyBoss script and create a few Global variables:
- _bossWaypoints = will be populated soon and contains our Waypoints.
- _randomWaypoint = the random waypoint to go to next
- _bossSpeed = the speed at which the Boss moves
Then we’ll utilize these in the Boss’s Movement() function, which is called in the Update() function:
So when the Boss reaches any destination, it will then choose a random destination from our Array then move towards the new _randomWaypoint.
- * Inside my if statement conditions, the sign “||” denotes the keyword “or”. So if it reaches waypoint 0 OR 1 OR 2, then it will choose a new waypoint.
Creating the Waypoints
Next we have to create the waypoints that our Boss will go to. We do this by creating 3 Empty Game Objects with coordinates (their transform position) we want the Boss to move to.
I placed them in another Empty Parent Object for tidiness:
Each Waypoint has a different transform:
After creating these empty Waypoints, we then need to link them to our Boss Inspector:
For the starting Waypoint, I chose to make the Boss go to ‘C’ first because it’s the lowest point the Boss will go, giving the Player a good reference point.
You can choose the Boss’s starting waypoint in the Inspector, or through code in the Start():
If done correctly, your Boss (or any other Enemy you choose) now uses a Waypoint system to navigate in-Game! This is just a basic system, but works very well for our 2D Space Shooter!
In the next article we’ll give the Boss the ability to shoot some projectiles!