I had never touched creating AI before this project meaning I was wary of how much of a challenge it would prove to be. I had allocated 10 days on my production schedule to develop the AI and yet I managed to make a basic system in only 3 days.
I knew that I was going to use a state machine method to create my AI, rather than a behaviour tree due to their simplicity and because I knew I didn't not require very complex AI, which is where a behaviour tree shines. Within the state machine method, however, I found that there were two main methods of implementation for Unity. You can have all the logic handled in one comprehensive script utilising coroutines or you can split the logic up into state behaviour scripts that sit on the states in the AI agents animator.
I began by attempting the one script method as I thought this would be cleaner, however, I quickly decided to switch to using the state behaviour method as the ability to make use of Unity's OnStateEnter and OnStateExit functions to better control logic, behaviour and parameters was too useful to pass up. Choosing this method impacted the animation controller of the enemies, rather than having one similar to the player that has states related to motions the enemies have states related to their behaviours.
The 'Chase' and 'Retreat' states have the same animation within them but hold different behaviour logic, whereas in the player's controller this would just be a 'Run' state.
As with the player movement script I made sure that the scripts inspector was clean and easy to understand and enables a good amount of customisability and functionality so that it can potentially be used for multiple enemy types if I choose to add them.
I have added functionality allowing the agent to have multiple attack animations that are randomly chosen to vary the attacks, the front arc of the agent, used to determine if an attack can be initiated or if they need to turn to face the player, can be altered. There are also constraints that allow me to alter behaviour at runtime and there is a system that allows the agent to shout taunts during combat, the system works with or without audio and lines can be easily added, removed, or edited.
The next step is to get the players systems and the AIs systems to talk to each other, giving and receiving damage, dying, status effects etc. However, I am very pleased with what I have managed to accomplish in 3 days for my first attempt at creating AI myself.
Comments