Behaviour tree is a tree structure for clarifying behaviour priorities and conditions and facilitating control.
In Arbor, you can use state machine by adding BehaviourTree to GameObject.
Example: Enemy whose behavior changes depending on the distance to the player
Let's consider an enemy AI, for example.
- It approaches if the distance between the enemy and the player is within 10 meters.
- Otherwise, it moves on a fixed route.
Behavior to approach the player can be said to have a high priority in comparison with the behavior of moving the fixed route.
Temporarily assembling with Arbor's Behaviour Tree will be as follows.
The higher the priority of the node on the left, the lower the priority on the right.
Also, by adding a script called Decorator to the node, we judge the condition and control the node to be executed.
We will do detailed comment later.
The nodes used in the behaviour tree are summarized in the following pages.
Please refer once before explaining each part.
Explanation of examples
Let's take a look at the previous example again.
- Beginning with the root node.
- With the Selector node, we will look for the successful node of the child node and execute it from left to right.
- In the Agent Move To Transform node, since the ParameterCheck decorator has been added, judgment is made on the condition of Parameter.
- As an example, the distance to the player is created assuming that it is stored in the Distance parameter.
- Assuming Distance is 15, the ParameterCheck decorator returns false, so the Agent Move To Transform node fails and returns to Selector.
- The Selector executes the next Agent Move On Waypoint node because the Agent Move To Transform node failed.
- The Agent Move On Waypoint action continues to run repeatedly unless an interruption or the like occurs because Type is set to Cycle.
- Let's set the Distance parameter to 10 or less.
- Agent Move To Transform interrupts the current node because it matches the ParameterCheck condition of the node.
- Again by making the Distance parameter greater than 10 you can see that the Agent Move To Transform node is interrupted and the Agent Move On Waypoint node becomes active.
How the active node changes by Distance parameter
As you can see, the execution priority gets lower as going to the right, and you can see that interrupts etc. can be done by Decorator of the node with high priority.
Even if it is a simple example like this time, even a finite state machine can be assembled without making it particularly complicated,
In the case where the number of states is large and the condition is likely to be complicated, it becomes possible to combine state transitions that are easier to maintain because the condition tree can be described on the execution node side without the transition lines crossing in the behavior tree in the behavior tree.