Game Development Reference
In-Depth Information
Handling state transitions and state requests
During an update, we need to check whether a transition is already being processed or
whether we even have another state to transition to. If there is a next state, and no transition
is processing, we check to see whether the blend window has passed so that we can start
transitioning into the next state.
A special case is added to hand transitions moving to another state even though there is no
explicit transition to that state. While handling this case isn't entirely necessary, it allows
the ASM to finish playing the current animation before processing a request to a new state
that has no explicit transition:
Sandbox.lua :
function AnimationStateMachine.Update(
self, deltaTimeInMillis, currentTimeInMillis)
local deltaTimeInSeconds = deltaTimeInMillis/1000;
local currentTimeInSeconds = currentTimeInMillis/1000;
if (self.currentTransition_ == nil and self.nextState_)
then
local currentAnimTime =
Animation.GetTime(self.currentState_.animation_);
local currentAnimLength =
Animation.GetLength(self.currentState_.animation_);
if (self:ContainsTransition(
self.currentState_.name_,
self.nextState_.name_)) then
local transition =
self.transitions_[self.currentState_.name_]
[self.nextState_.name_];
if ((currentAnimTime + deltaTimeInSeconds) >=
(currentAnimLength -
transition.blendOutWindow_)) then
Search WWH ::




Custom Search