- Home /
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%?
Answer by Waz · Jun 25, 2011 at 01:54 AM
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.
Thanks. I was thinking of weight as just an input value, but it is also a control value while the clip is playing, and CrossFade always blends from the current weight to 100%. It makes sense now.
Answer by ddd.du · Jun 28, 2011 at 01:00 AM
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
No, definitely not the way to go. That would cause the combinatorial explosion in animations that blending is designed to prevent.
Your answer
Follow this Question
Related Questions
Play 2 animations at once 4 Answers
Play an animation just on some parts of the body 1 Answer
What am I not getting about animation weight blending? 4 Answers
Animation Layering 2 Answers
How to use CrossFade with anim2 when anim1 is over? 1 Answer