Building a behavior tree
Building a behavior tree is very similar to building a decision tree, except for the addition of selectors and sequence node types.
We can start creating a behavior tree using a similarly wrapped function that instantiates a behavior tree and creates the first selector node for the tree:
SoldierLogic.lua
:
function SoldierLogic_BehaviorTree(userData) local tree = BehaviorTree.new(userData); local node; local child; node = CreateSelector(); tree:SetNode(node); return tree; end
The death behavior
To add the first action, which is death, we add the required sequence, condition, and action nodes. As the behavior tree will completely re-evaluate once an action completes, we don't have to worry about other actions knowing about death. As prioritizing actions is based on how early in the tree they appear, we add death first, because it has the highest priority:
SoldierLogic.lua
:
function SoldierLogic_BehaviorTree...