Road to Game Dev: The Final Boss. (Part 6: Mother Brain)

Rowan Mcmanus
3 min readOct 9, 2021

With all of the attack patterns together, the final and most important step is to create the master AI for the boss itself. For organization purposes, I’m attaching the “brain” code to a separate object, and having it simply call the attacks on the boss with an “AI Commander” function, which serves as a simple switch statement.

As an organizational tip, I highly recommend creating a spreadsheet that will help you keep track of the ID’s for each attack and turret, and what attacks can happen in which phase. Here’s an example of what mine looked like at the end:

Creating the Basic Brain

Like before, the best place to start is knowing what you need the brain to do. Selecting attacks, firing multiple attacks at once, and remembering what its doing. The last bit seems strange at first, but you have to remember that computers are actually pretty dumb; if we tell it to fire an attack while an attack is already going, weird things can happen.

Firing multiple attacks at once presents some interesting challenges; we can’t simply wait for a while after an attack to fire the next one, since then things can break. Instead, we need each attack to have its own managed cooldown. We also need to be checking every frame if we can fire an attack, and know when an attack was fired successfully.

Attack Memory

The next major challenge is for the boss to actually remember not only what it’s doing, but what it’s allowed to do. This serves a dual purpose; it prevents bugs from happening when two attacks use the same component, and prevents the same attack from firing multiple times in a row. To manage this, we need an array that stores the ID’s of recently used attacks, and a function on the components that we can use to ask if they have another attack in progress or not. This gives us a lot of control over which attacks we can use; here’s how the randomizer changes:

Once an attack is successful, it also calls one additional function that manages the list of recent attacks.

Completing the Boss

Once the controllers are completed for each phase, the last step is to bugtest, and then pat yourself on the back for a job well done! This is the first step towards a complicated boss AI, and AI that can read the state of the game. There are a number of other smaller functions that you may need to handle small aspects of the boss, but none of these cover anything we haven’t already learned before.

This is the final part of the final boss series! Soon, I’ll be writing devlogs for a brand new project in the 3D space.

--

--