Phase 2: Boss AI Part 3

Simon Leen
3 min readJul 13, 2021

--

Objective: Set up the states for our Boss Enemy and finish the game when the Boss is destroyed.

In the previous post we set up our Boss prefab and initial states.

We set up BossState enum states:

  1. Arriving (when the boss spawns at the end of the final wave)
  2. SpawnPos (Moving from center screen up to where the boss starts spawning enemies)
  3. Spawning (The boss spawns 2 sets of 2 enemies)
  4. AttackPos (The boss moves towards the top left corner getting ready for a laser attack)
  5. Attack (This will be where the boss travels from the left side of the screen to the right while shooting double lasers)
  6. Recharging (The boss will start to move back to the spawn position without shooting or spawning)
  7. Vulnerable (The boss does a chargind sequence)
  8. Won (The boss and enemies have destroyed the player)

We have some of our usual set up sequence, creating and assigning objects, audio and variables as in previous posts.

In the Update method we use a switch statement using the enemies currentState to swap being Boss States. On arrving the boss will move into the center screen. When it reaches a particular point on the Y-axis it will trigger a coroutine that will wait 2 seconds in that position bedore changing state to SpawnPos. This will move the boss back up the Y-axis and into position to start spawning enemy ships.

Upon reaching the Spawn pos it triggers a Spawner coroutine which spawns 2 enemies, one from each side, waits 2 seconds then spawns 2 move and all while moving from the SpawnPos to the top left which is the AttackPos.

Once there it will trigger an AttackReady coroutine and plays a laser charge sound then changes state to Attack.

The attack state triggers an EnemyFire method that fires lasers while moving across the screen. Once the boss reaches a certain point on the X-axis it switches from attack to recharging. During this rechartging state the boss moves from the right side of the screen back towards the center, stopping halfway on a triggered coroutine that sets off the charging sequence(When the boss is most vulnerable) and sets the start to Vulnerable.

If the boss is not destroyed by now the charging coroutine sets the boss state back to SpawnPos and cycles throught the states again until the boss or player are destroyed. If the player is destroyed the boss state is swithches to won and spawning of powerups and enemies is stopped.

If the boss is destroyed the spawning of powerups is stopped and the gameover sequence is called from the UIManager and sets a great tint on the screen as opposed to the red tint when the player is hit or dies.

We have a BossDamage method set up for adding fire and smoke to the boss on each hit. the boss has a health value of 10. Lasers take 1, an EMP blast takes 2 health and missiles can’t track or damage.

We also added a new text element to the canvas for the boss health which gets activated when the boss is instantiated and updates on each hit. I have set it so that when the boss is destroyed it triggers a destroy all enemies method that uses a foreach similar to when setting up the missile.

For the next post, I will be moving on to Cinematography with Unity but I may come back and redo the UI, Game Assets and some more adjustements later.

--

--

No responses yet