I’ve spent a lot of time researching, reading, scrolling and designing this project. So far I have learned a lot of things, especially about OO principles, complexities of behaviour trees and also the usefulness of UML class diagrams. However, I am still not entirely convinced my UML is correct and it is certainly not finished.
Currently, I have scripted a few of the behaviours that will be triggered through the behaviour tree (in order to have something to demo). Three of the main movement systems – move, wander and patrol – are fairly similar in their execution, but are dynamic in that the agent can wander from where they are, rather than a specific point. Similarly, the patrol takes the current position of the Agent (or group later) and then creates 6 points that the agent will loop through. The purpose of this would be so that if an enemy is spotted then the behaviour can be broken out of and the Agent will engage (after asking the Game Director what to do).
I was mostly following an extract from an AI Programming book until I realised I had purchased it in a humble bundle at the start of the year. (Unity 2017 Game AI Programming, 3rd Edition). It explains, in some depth, about the creation of an abstract node class which can then been implemented and overridden to create any type of Root, Composite, Decorator orLeaf node – as well as a few of the subtypes that inherit from those. From there I would be able to build the behaviour tree depending on the outcome I aim to create. Such as getting the sensor data from an agent and deciding whether to attack and how. For example, this could be a presented scenario.
Agent’s vision is triggered and the collider seen is of tag “Agent/Team2”
Send request to GameDirector asking what to do whilst passing the location spotted and this agent’s stats (health and courage etc), called something like EnemyAgentDetected.
GameDirector then goes to the tree that is created for the scenario given (EnemyAgentDetected) and then returns a State to the Agent. This state will determine the Agent’s behaviour
GameDirector will likely return either Attack or Flee. In which case the Agent will then execute the function if they are in that state. Let’s say for this example the Attack state is returned.
The Agent will first have to move to the target (calling that function), aim at the target then hit the target. It will stay in the attack state until the enemy is killed and the trigger is no longer…triggered.
Of course, I would have to figure out leaving states and reentering very quickly as this would be computationally expensive on every frame for every agent. I will also have to consider if there are more than one enemy, or if the Agent has allies within its communicable range. In which case, that data would also be sent to the GameDirector to which it might send all of the Agents in the communicable range of the initial Agent to attack the enemy. Else, if the Agent sees multiple agents and is alone, it may stay and fight, depending on health and courage, or it may flee. However, this might lead to boring behaviour, with only 1v1 fights ever occurring. It will need extensive testing, balancing and alterations.
Regardless of the difficulties, I really hope I can create a realistic and engaging AI system, capable of insertion into any game style appropriate, both in Unity or other engines.