Game Development Reference
In-Depth Information
Playing with states
We can now start playing with animation states within our ASMs. In this case, we have two
ASMs that need to be kept in sync, so we create a global weaponState variable that will
check whether our weapon is in the sniper rifle pose or the SMG pose.
Next, we can bind each of the number pad keys to request specific states within our soldier
and weapon ASMs. Special case handling is required for the transform states as well as the
reload state:
Sandbox.lua :
local weaponState = "sniper";
local function IsNumKey(key, numKey)
-- Match both numpad keys and numeric keys.
return string.find(
key, string.format("^[numpad_]*%d_key$", numKey));
end
function Sandbox_HandleEvent(sandbox, event)
if (event.source == "keyboard" and event.pressed) then
if (event.key == "f1_key") then
Sandbox.SetCameraPosition(
sandbox, Vector.new(0, 1, -3));
Sandbox.SetCameraForward(
sandbox, Vector.new(0, 0, -1));
elseif (event.key == "f2_key") then
UI.SetVisible(ui, not UI.IsVisible(ui));
elseif (event.key == "f3_key") then
displaySkeleton = not displaySkeleton;
Animation.SetDisplaySkeleton(
soldier, displaySkeleton);
elseif (IsNumKey(event.key, 1)) then
soldierAsm:RequestState("melee");
elseif (IsNumKey(event.key, 2)) then
if (weaponState == "sniper" and
soldierAsm:RequestState("reload")) then
Search WWH ::




Custom Search