A simple, finite state machine
Now that we've implemented the internals of each state, we can flush out the basic FSM that controls when each state function is to be called. We'll begin by getting some local variables out of the way and different flags for stance variation:
DirectSoldierAgent.lua
:
local _soldier; local _soldierAsm; local _soldierStance; local _soldierState; local _weaponAsm; -- Supported soldier stances. local _soldierStances = { CROUCH = "CROUCH", STAND = "STAND" };
Initializing the agent
Initializing our direct control agent is very similar to the other agents we created previously. This time, we add the ASM callbacks during the initialization so that our soldier will shoot during the fire
and crouch_fire
animation states. The Soldier_Shoot
function expects to receive a table that contains both the agent and soldier mesh in order to shoot projectiles and handle projectile collisions:
DirectSoldierAgent.lua
:
function Agent_Initialize(agent) -- Initialize the soldier...