This project is read-only.

CrossFade

May 22, 2010 at 4:22 PM

I've been using this code to switch smoothly between animations.

protected void UpdateInput(GameTime gameTime)
{
KeyboardState keyboardState = Keyboard.GetState();
KeyboardState lastKeyboardState = Keyboard.GetState();

if (keyboardState.IsKeyDown(Keys.A))
{
move -= 0.5f;
Component.AnimationController.PlayClip(Component.SkinnedModel.AnimationClips["Walk"]);
}

else if (keyboardState.IsKeyDown(Keys.D))
{
move += 0.5f;

Component.AnimationController.PlayClip(Component.SkinnedModel.AnimationClips["Walk"]);
}

else
{
Component.AnimationController.CrossFade(Component.SkinnedModel.AnimationClips["Stance"], TimeSpan.FromMilliseconds(300));
}

lastKeyboardState = keyboardState;
lookAtMe.myPosition = new Vector3(lookAtMe.myPosition.X, move, lookAtMe.myPosition.Z);
}

The idea here is that when the model starts/stops walking they move smoothly to/from  the stance animation. If I use the PlayClip on all three the transition is a bit too sharp. However, the solution above seems to be only playing the Walk animation. The Stance animation seems to be frozen, or perhaps only playing the first keyframe.  Have I made a mistake?