Game Development Reference
In-Depth Information
Doing
-- this assumes all possible states can
transitions to
-- both stances.
if (_soldierStance == _soldierStances.CROUCH)
then
_soldierStance = _soldierStances.STAND;
Soldier_SetHeight(
agent, _soldier, Soldier.Height.Stand);
else
_soldierStance = _soldierStances.CROUCH;
Soldier_SetHeight(
agent, _soldier, Soldier.Height.Crouch);
end
end
end
end
With the ability to change the soldier's state, it's time to spawn a new DirectSoldier-
Agent agent within the sandbox. We can add a key press handler in the sandbox script to
spawn a DirectSoldierAgent variation at a semi-randomized location:
Sandbox.lua :
function Sandbox_HandleEvent(sandbox, event)
if (event.source == "keyboard" and event.pressed) then
if ( event.key == "f1_key" ) then
local agent = Sandbox.CreateAgent(
sandbox, "DirectSoldierAgent.lua");
agent:SetPosition(
agent:GetPosition() +
Vector.new(
math.random(-5, 5), 0, math.random(-5,
5)));
end
end
end
Search WWH ::




Custom Search