Game Development Reference
In-Depth Information
Attaching an animated mesh to an agent
First, we'll attach a soldier mesh to an actual agent. The only difference while creating a
mesh in this fashion is passing the agent into the Core.CreateMesh function instead of
the sandbox. This allows the sandbox to automatically update the mesh based on the agent's
position and orientation.
As the sandbox automatically updates the mesh's position and orientation based on the
agent's forward direction, we will always consider the agent's forward vector as the vector
of movement and not necessarily the direction the agent is facing. Intuitively, this division
will allow our agent to move backwards, for example, while still having the mesh facing
forward:
SoldierAgent.lua :
require "Soldier"
local _soldier;
local _soldierAsm;
local _weaponAsm;
function Agent_Cleanup(agent)
end
function Agent_HandleEvent(agent, event)
end
function Agent_Initialize(agent)
-- Initialize the soldier and weapon models.
_soldier = Soldier_CreateSoldier(agent);
local weapon = Soldier_CreateWeapon(agent);
-- Create the soldier and weapon animation state
machines.
_soldierAsm =
Soldier_CreateSoldierStateMachine(_soldier);
_weaponAsm = Soldier_CreateWeaponStateMachine(weapon);
Search WWH ::




Custom Search