Definition:
Its a technique that can be used to control behavior of NPC that utilizes a Tree structure the logic used by the AI. As any tree, there’s one single unique single root and from it expands with nodes and leaves.
- Composite Nodes: is one node that can have one or more children nodes
- Sequence: Will ensure that each child is visited in order to select a node. Note that the sequence can be abandoned.
- Selector: Indicates that only one child need to be visited and that child can be picked at random.
- Decorate Node: can only have one child
- Leaf Node: Is a node at the end of a branch that corresponds to an actual self contained action. A group of leaf nodes at the end of a branch may represent a sequence of actions or a set of actions depending of the type of composite node who parents it.
“The behaviour tree itself is kind of scripting language sitting above the code base.”
“A Leaf node must have a matching method that can be executed … The method itself will have to report whether or not it has failed or succeeded. This gives the leaf node a fail or success state, which is reported back to the running of the behavior tree. In the case of a sequence, this is essential as if a single one fails, the entire sequence fails”
For this is used a delegate method. This is a clever approach since reduce the number of classes necessary for constructing the behavior tree.
“So basically what it comes down to is that a sequence node is like a logical “and” if all of its children are successful, then the sequence node actually returns successful to its parent. If any of the children fail one or more of them, then the sequence node itself fails and it reports a final back up the tree to its parent.”
This means that the nodes will be tested in a “breadth first way”. A sequence node execution will be considered a success only if all their children are successful.
“A selector is an OR statement, so only needs to one of the things to be successful. So as it goes through its list of children, if one fails, it will keep trying until it either gets to the end or one of them is successful because that’s all it needs.”
“The condition is really just another leaf, like an action, but it is much simpler because rather than doing any particular process it’s just testing a certain value”