Game Development Reference
In-Depth Information
Agent FSM state handling
All the actual FSM states get handled during the update loop. The direct control soldier is
very similar to other agents except that it handles which of the state functions we call. As
this is a very simple FSM without a real system providing state updates, all that you need to
do is match which state the soldier is in and call the appropriate function. Some checks for
death and falling occur before this happens, as they take precedence regardless of what the
agent actually wants to do:
DirectSoldierAgent.lua :
function Agent_Update(agent, deltaTimeInMillis)
-- Returns the amount of time that has passed in the
sandbox,
-- this is not the same as lua's os.time();
local sandboxTimeInMillis = Sandbox.GetTimeInMillis(
agent:GetSandbox());
-- Allow the soldier to update any soldier's specific
data.
Soldier_Update(agent, deltaTimeInMillis);
-- Update the animation state machines to process
animation
-- requests.
_soldierAsm:Update(deltaTimeInMillis,
sandboxTimeInMillis);
_weaponAsm:Update(deltaTimeInMillis,
sandboxTimeInMillis);
-- Draw the agent's cyclic path, offset slightly above
the
-- level geometry.
DebugUtilities_DrawPath(
agent:GetPath(), true, Vector.new(0, 0.02, 0));
-- Ignore all state requests once the agent is dead.
if (agent:GetHealth() <= 0) then
Search WWH ::




Custom Search