Framework 2: Boss Ai (part 1)

Creating the ground works for a Stronger, smarter Enemy

Simon Truong
3 min readJun 22, 2021

--

Now that we have reached the end at the 3rd and final level. Its just you, your ship, and a big bad Boss. Since we can’t have the boss just randomly sit there and let you take pot shots at them, it is time to create some Ai. In part 1, we will focus on setting the ground works which includes understanding a State machine and setting up a single state for movement.

What we will be needing for this setup is a brand new Script which will be the Boss Behavior script and a graphic that can represent itself as … well, represent itself like a boss figure. (evil one at least)

The Graphics

For my boss, instead of shapes or space ships, I decided to go far into the imaginary scope and picked Alien spacecraft! (I am fun at parties I swear)

Credit goes to PNGEGG for the file, link can be found here.

I also added some minor animation to make it slightly more daunting.

The Boss Ai Script

Create a new script and drag the script into the Boss game object. In the script we are going to start out with the basic values that we have been giving every other enemy so far. This includes Health, speed etc.

Next we are going to create an Animation, this will be the starting point of our simple state machine.

What is a state machine you asked? Well a state machine is basically a more complex IF statement. When something happens or if the player triggers and certain event, it can trigger certain states within the enemy state machine.

Another very good visual example of what an state machine is would be the Unity Animator.

When setting up an Parameter, you are giving an condition to a state to fulfill before you can transfer to another state. In the example above, the “Fire Laser” parameter must be triggered before the “Boss_noFire” can travel to “Boss_charged Laser” state.

In fact, since Unity has provided us with such a powerful visual tool, we are going to use that instead of creating our own. (why re-invent the wheel?)

Since we have already created our first animation, we should have an active Animator within the Boss game object. What we want at the end is to create a more complex map within the Unity Animator by providing more animation states. An example would be, an idle state, serval attacking state, and finally a death state.

You can add more animation states by clicking the top left drop down menu in the Animation window and clicking “Create New Clip…” This will automatically create a new animation clip and also a new state within the Animator.

This wraps up part 1 of the Boss Ai tutorial, since this will be a quiet a long read/write, more will be on part 2.

--

--

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.