This section will archive the AI-related scripts I have created and explain their use.Â
NPCBehaviorChangersList.cs
This script keeps track of the traits assigned to AI throughout the level. It updates the list when a new AI is created or removed.
NPCFactory.cs
This script handles the spawning and despawning of AI prefabs, upkeeping lists of those prefabs, assigning traits, and the logic of finding a spawn able point near the hand placed spawn zones.
NPCMove.cs
This script handles the general behavior of the AI. It assigns them a behavior based on their traits and containts the logic that allows these Ai to interact with each other. This is also where the logic behind the "AI running away" system is coded, in FindEscape(). When it comes to finding other AI, this script changes depending on the traits of the current AI as well as the AI near it. The general idea is that the variable "Min" is meant to be a slot representing the nearest AI that fits the current criteria. So if this AI is a chaser, GetClosestNONSCARYNPC() is run, which will then store the nearest NPC without the scary trait in Min. The current AI will then navigate towards that AI. "Min" is updated on a once per second basis, allowing for adaptability with the AI as well as preventing these checks from being too resource intensive. This script also handles the AI's lifespan logic, as well as some debug text to help with testing. If there are no special behaviors necessary, the AI will just default to the Roam() method, which simple has them wander around the navigatable area