Game Development Reference
In-Depth Information
Shooting
Getting our agent to shoot ends up with an ASM callback function that shoots a bullet each
time the fire animation plays. The position and rotation of the muzzle bone is looked up
and a single bullet is fired by the Agent_ShootBullet function:
SoldierAgent.lua :
local function _Shoot(stateName, callbackData)
local agent = callbackData.agent;
local sandbox = agent:GetSandbox();
local soldier = callbackData.soldier;
local position =
Animation.GetBonePosition(soldier, "b_muzzle");
local rotation =
Animation.GetBoneRotation(soldier, "b_muzzle");
_ShootBullet(sandbox, position, rotation);
end
function Agent_Initialize(agent)
...
-- Data that is passed into _Shoot, expects an agent,
and
-- soldier attribute.
local callbackData = {
agent = agent,
soldier = _soldier
};
-- Add the shoot callback to handle bullet creation.
_soldierAsm:AddStateCallback(
Soldier.SoldierStates.STAND_FIRE, _Shoot,
callbackData);
end
Search WWH ::




Custom Search