Game Development Reference
In-Depth Information
Building a finite state machine
To build a finite state machine for our agent, we'll create the initial states that wrap each
possible action. As the state machine needs a starting point, we'll set the state explicitly to
the idle state to begin with. Once the idle state has finished, our state machine will automat-
ically pick the most relevant action to execute afterward:
SoldierLogic.lua :
function SoldierLogic_FiniteStateMachine(userData)
local fsm = FiniteStateMachine.new(userData);
fsm:AddState("die", DieAction(userData));
fsm:AddState("flee", FleeAction(userData));
fsm:AddState("idle", IdleAction(userData));
fsm:AddState("move", MoveAction(userData));
fsm:AddState("pursue", PursueAction(userData));
fsm:AddState("randomMove", RandomMoveAction(userData));
fsm:AddState("reload", ReloadAction(userData));
fsm:SetState("idle");
return fsm;
end
Search WWH ::




Custom Search