Reader small image

You're reading from  Learning Game AI Programming with Lua

Product typeBook
Published inNov 2014
Reading LevelBeginner
PublisherPackt
ISBN-139781783281336
Edition1st Edition
Languages
Right arrow
Author (1)
David Young
David Young
Right arrow

Creating a behavior tree agent


To use our behavior tree, we can replace the finite state machine and perform the same update loop on our behavior tree instead. Regardless, if our agent is using a decision tree, state machine, or behavior tree, its actions will be nearly identical, as the logic is merely translated from one decision structure to another:

IndirectSoldierAgent.lua:

local soldier;
local soldierController;
local soldierBT;
local soldierUserData;

function Agent_Initialize(agent)

    ...
    
    soldierBT = SoldierLogic_BehaviorTree(
        soldierUserData);
end

function Agent_Update(agent, deltaTimeInMillis)
    if (soldierUserData.alive) then
        soldierBT:Update(deltaTimeInMillis);
    end

    soldierController:Update(agent, deltaTimeInMillis);
end
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning Game AI Programming with Lua
Published in: Nov 2014Publisher: PacktISBN-13: 9781783281336

Author (1)