Animation: Impact of combining the use of Layer, CrossFade, and Weight

This question has to do with how combining layers, cross fade, and weight effects an animation.

Introduction Topic: Animation Scripting

Scenario

Clip: Idle

  • Default Clip
  • Looping
  • Default Layer

Clip: Wave

  • Non-looping
  • Not assigned to animation object.

About 5 seconds into the simulation, the following code is run:

mAnimation.AddClip(waveClip, mClipName);
mAnimation[mClipName].layer = 100;
mAnimation.CrossFade(mClipName, 1.0f);

As expected, the wave clip fades in from 0 to 100% over 1 second, then fades back out. The idle animation continues un-interuped.

The Unexpected

Same scenario, except with the following code:

mAnimation.AddClip(waveClip, mClipName);
mAnimation[mClipName].layer = 100;
mAnimation[mClipName].weight = 0.5f;  // <- Changed here.
mAnimation.CrossFade(mClipName, 1.0f);

What I expect is the same behavior, except that the wave clip will fade in from 0 to 50%.

What is actually happening is that it fades in from 50 to 100%, so I get a sudden snap at the beginning of the crossfade.

Question

Is this behaving as expected? If so, what is the logic behind this behavior? And what should I do if I really want to fade in from 0 to 50%?

CrossFade operates by modifying the weight (watch it change in your first code to see this). By setting the weight to 0.5 initially, you are effectively jumping the crossfade forward.

One way to get the 0 to 50% would be to put it on a lower layer and set the idle animation weight to 0.5.

Better might be to use Animation.Blend.

just create a separate animation just like what they did on bootcamp demo, idle, idlewhilewave, walk, walkwhilewave, etc.,Just A Suggestion Just Create A Seperate Animation Like What They Did On BootCamp Demo idle, idlewaving, walk, walkwaving, etc