Capstone: Month 1 Week 4

This post covers the 4th week of our Capstone project.

This Week’s Tasks

This week I was tasked with:

  • Implementing the Initial Enemy AI
  • Implementing the Health System

Enemies

Screenshot showing overhead view with AI debug gizmos
While fairly simple on the surface, the Enemy system I’ve implemented has a fair amount going on under the surface. The Enemies have a dynamic vision range, so that when idle they will become ‘aggro’ when a player comes near, but once they have aggro they will track the player at a further distance. Additioanlly, once the player shoots at them, they gain an extremely large vision range so that the player can’t safely shoot from outside of their movement range. This will likely still need to be balanced based on our map size, and used in conjunction with good map design without extreme sight lines that allow the player to gun down enemies without any difficulty. The Enemies also track the last place they saw a player in their vision range. In the case that the Enemy loses sight of the player, it will go to this ‘last seen position’, and if they still cannot find the player again, will return to their home position.

As for implementation details, I’ve created an ‘Enemy’ base class, which each enemy type will inherit from & override relevant functions (in this case, the ZombieEnemy class). This pattern of inheritance allows us great flexibility and should scale extremely well to however many enemy types we require. The enemies movement is implemented using NavMeshAgents. I’ve also created a few debug gizmos so you can tell what the AI is doing while inside the editor, which has been very helpful for debugging. Finally, I am considering implementing a state machine for the Enemy AI moving forward, assuming that we will want more complex AI behaviour in the future.

Health System

Code Snippet of the Damage Function from the Health System
The health system was created in a modular way so the same script can be used on both the Player and enemies with no modification. This initial implementation is already rather robust, so I don’t expect I will need to revise it much going forward. There is all the typical methods you would expect (Damage, Heal, Revive, Die, OverideHealth, etc.), as well as functionality that updates the UI on an as-needed basis, and a function that notifies the relevant party of a health change.

I also created a ‘pick-up’ item that upgrades your maximum health. These will be placed throughout the level.