2D Certification: Boss AI
In the last article, I added a homing projectile. Today, I’m going to be finally finishing the second, and final, phase of the GameDevHQ 2D Game Development Certification track. In this article, I’ll be adding Boss AI! The requirement reads as follows:
- Create a final wave that includes a boss at the end. * Moves down the screen to the center and stays there. * Unique attacks towards the player
The boss battle is the requirement I was both most intimidated by and most excited to work on. I decided to kitbash a new enemy from a combination of the other enemies sprites and came up with something that looked really cool!
I also updated some of the sprites for other enemy types while I was at it to try to give the game a cohesive feel while still providing some variety.
With graphics, colliders, and rigid bodies in place it was time to add the script to my new boss prefab. I started with the requirement that the boss moves to the center of the screen when it enters. To control this I created a boolean that is set to false when the boss reaches the center of the screen. I then created a method to be called on update as long as the boolean was true.
Next was to handle the motion and firing routines for the boss. for motion I created a unique way point path and assigned it to the boss wave and well as attaching the enemy pathing script to the boss. I also changed the waypoint movement code in the boss slightly to loop backwards over the waypoints when it reaches the end waypoint instead of destroying itself. I added a pause at each waypoint and had the boss begin firing at each pause.
I gave the boss more health than a standard enemy which can take one hit without shields. and wrote the collision code to reduce the boss’s health by a fixed amount each time it was hit. This is another place that I would like to come back and refactor a few things to make damage variable based upon the projectile that hits the boss. At some point i’d like to give each enemy a life point based health instead of one hit too.
Lastly, I created a win screen scene to be loaded upon the bosses death. The win screen contains a scrolling list of credits and thank you’s to people who helped me on my journey so far.
In this article, I added Boss AI. Next time, I’ll be starting a look at how to make my games in Unity more beautiful! If you enjoyed this article, or want to come along with me as I progress on my journey, follow me at gamedevchris.medium.com.