The Boss Enemy, Part 3

Blake Zoeckler
3 min readJun 17, 2021

--

Objective: give the boss another attack pattern with beams

The next attack pattern will be create through a new BossState called BeamAttack. The goal here is to have beam weapons that track the player as they charge, then fire on the player position after a brief delay. We’ll need to set up the gameobjects in the hierarchy and have variables in BeamAttack to keep track of them.

In order to organize all these game objects, we’ll use a struct. This is similar to class, except that it’s mainly used for holding data. By making the struct serializable and then serializing all the fields, we are able to set all these game objects in the inspector to keep track of them.

Now we can utilize these game objects similarly to how the dodging enemy uses its beam attack. Since we want to allow the boss to track the player, wait a moment, and then fire, we can use a finite state machine within this state class!

BeamAttack enum. It’s a state machine within another state machine.

To setup this attack, we’ll start in the Tracking state, set the charging sprites to zero scale, and start the warning line flashing for both beams. We also make sure to keep track of the rotation of the entire beam objects so we can control them as they track the player.

BeamAttack.Setup

This coroutine causes the warning lines to flash. They will flash faster once the beams have “locked on”, in order to let the player know they are about to fire!

While tracking, we increase the size of the charging sprites over time, while also rotating the beams toward the player (as long as the player exists of course). We use a new EnemyBehavior helper method to rotate the beams in the proper directions.

BeamAttack methods
EnemyBehavior.RotateToVector

Finally, when the state is changes to locked, we will wait some time and then change to the Fire state. This calls FireBeams which turn off the charging sprite and turns on the actual beam attacks that can damage the player.

BeamAttack methods

Finally, when the boss leaves the BeamAttack state entirely, it will call EndState which turns off the beam attacks and resets their rotations, to ensure they will be set up properly for the next time the boss uses this beam attack.

BeamAttack.EndState

Now the boss has a pair of deadly new weapons in its arsenal, and extremely flashy ones at that!

--

--

Blake Zoeckler
Blake Zoeckler

Written by Blake Zoeckler

I’m a passionate and talented software engineer seeking an opportunity in game development.

No responses yet