Behavior tree structure

-
BT Node:
-
the base node in the behavior tree. The node will have behavior for each update frame during gameplay, and return the node’s status, like running/success/fail.
-
-
-
Condition:
-
The condition node that will be used in the condition filter. The condition takes one bool func and returns the node status based on the bool func, success if true or fail if false.
-
-
Actions:
-
The behavior logics of the behavior trees. The action nodes will be implemented specifically based on the NPC’s behaviors.
-
-
Composite Node:
-
The branch node in the behavior tree. The composite node will contain children nodes and operate behaviors based on its children nodes.
-
-
Sequence:
-
The sequence node is an implementation of a composite node. A sequence executes its children nodes in order, and returns fail status if any child node fails or continues until all children nodes succeed.
-
-
Selector:
-
The selector is an implementation of a composite node. The selector will execute its children nodes in order, and return success status if one node succeeds or return fail status if all children nodes fail.
-
-
Condition Filter:
-
A specific sequence. the sequence will take a condition node as the first node to check if the sequence can be entered.
-
-
Priority Selector:
-
A specific selector node. It ensures that the highest-priority executable child node is always executed, with priority determined by the order in which the children are added.
Enemy AI
Behavior trees are typically used for the logic AI of NPCs or player characters. In this practice, I want to create an enemy AI with the following features:
-
idle in normal situation
-
guard toward the player and walk randomly when the player get close to guard range
-
randomly pick one attack
-
attack combo 1
-
attack combo 2
-
heavy attack
-

Final Effect
Code Sample


