Game Development Reference
In-Depth Information
Playing a non-looping animation
Playing a non-looping melee animation while our soldier is already playing an idle anima-
tion takes a bit more effort than simply enabling a second animation. First, we need to dis-
able looping on the melee animation, and then disable the animation completely during ini-
tialization.
Next, during the update loop, we determine whether the melee animation has completed; if
it did complete, we disable the melee animation, reset its timing, and enable the idle anima-
tion.
To get our soldier to the melee on a command, we bind the e_key string to enable the
melee animation and the idle animation:
Sandbox.lua :
local meleeAnimation;
function Sandbox_HandleEvent(sandbox, event)
if (event.source == "keyboard" and
event.pressed and
event.key == "e_key") then
if (not Animation.IsEnabled(meleeAnimation)) then
Animation.Reset(meleeAnimation);
Animation.SetEnabled(meleeAnimation, true);
Animation.SetEnabled(idleAnimation, false);
end
end
end
function Sandbox_Initialize(sandbox)
idleAnimation = Animation.GetAnimation(
soldier, "stand_run_forward_weapon");
-- Allow the animation to affect the soldier's skeleton.
Animation.SetEnabled(idleAnimation, true);
meleeAnimation = Animation.GetAnimation(
Search WWH ::




Custom Search