O'Reilly logo

Learning Game AI Programming with Lua by David Young

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Building a behavior tree

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;
end

The death behavior

To add the first action, which is death, we add the required sequence, condition, and action nodes. As the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required