Creating a behavior tree object
Creating a behavior tree object is simple, as it primarily consists of a root node, evaluation function, and update function:
BehaviorTree.lua
:
require "BehaviorTreeNode" BehaviorTree = {}; local _EvaluateSelector; local _EvaluateSequence; function BehaviorTree.SetNode(self, node) tree.node_ = node; end function BehaviorTree.new() local tree = {}; -- The BehaviorTree's data members. tree.currentNode_ = nil; tree.node_ = nil; return tree; end
Behavior tree helper functions
Four primary evaluators are used to process the behavior tree structure: selector evaluation, sequence evaluation, actual node evaluation, and finally, a continue evaluation function that continues where a sequence's child finishes:
BehaviorTree.lua
:
local EvaluateSelector; local EvaluateSequence;
Selector evaluation
As selectors only return false if all child nodes have executed without returning true, we can iterate over all children and return the first...