-
Book Overview & Buying
-
Table Of Contents
Learning game AI programming with Lua
By :
Building a behavior tree is very similar to building a decision tree, except for the addition of selectors and sequence node types.

The soldier's behavior tree
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;
endTo 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...
Change the font size
Change margin width
Change background colour