Game Development Reference
In-Depth Information
Forcefully setting states
Now that we have states and transitions, we need to be able to set the state of the ASM at
any time. For this, we need to clear out any currently playing animations and set the current
state while initializing the state's animation.
Note
Forcefully setting an ASM's state will immediately begin playing the animation for the set
state. This will typically create an undesired pop for the requested animation.
Our SetState function will mainly be responsible for clearing a playing animation, and then
immediately applying the animation for the corresponding forced state.
Sandbox.lua :
function AnimationStateMachine.SetState(self, stateName)
if (self:ContainsState(stateName)) then
if (self.currentState_) then
ClearAnimation(self.currentState_.animation_);
end
if (self.nextState_) then
ClearAnimation(self.nextState_.animation_);
end
self.nextState_ = nil;
self.currentTransition_ = nil;
self.transitionStartTime_ = nil;
self.currentState_ = self.states_[stateName];
InitializeAnimation(self.currentState_.animation_);
end
end
Search WWH ::




Custom Search