Game Development Reference
In-Depth Information
Initializing the agent
Initializing our direct control agent is very similar to the other agents we created previ-
ously. 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 and weapon models.
_soldier = Soldier_CreateLightSoldier(agent);
local weapon = Soldier_CreateWeapon(agent);
-- Create the soldier and weapon animation state
machines.
_soldierAsm =
Soldier_CreateSoldierStateMachine(_soldier);
_weaponAsm = Soldier_CreateWeaponStateMachine(weapon);
-- Data that is passed into Soldier_Shoot, expects an
agent,
-- and soldier attribute.
local callbackData = {
agent = agent;
soldier = _soldier
};
-- Add callbacks to shoot a bullet each time the
shooting
-- animation is played.
_soldierAsm:AddStateCallback(
Soldier.SoldierStates.STAND_FIRE,
Soldier_Shoot,
callbackData);
_soldierAsm:AddStateCallback(
Soldier.SoldierStates.CROUCH_FIRE,
Search WWH ::




Custom Search