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 finite state machine agent


Now that we've created a finite state machine, we can simply replace the decision tree that powers our indirect soldier agent with a finite state machine. The initialization, updating, and termination of our FSM are identical to the decision tree.

With an abstract data structure, we can now create both decision-tree-based agents and finite state machine agents simultaneously:

IndirectSoldierAgent.lua:

local soldier;
local soldierController;
local soldierFSM;
local soldierUserData;

function Agent_Initialize(agent)

    ...
    
    soldierFSM = SoldierLogic_FiniteStateMachine(
        soldierUserData);
end

function Agent_Update(agent, deltaTimeInMillis)
    if (soldierUserData.alive) then
        soldierFSM: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)