- Home /
Animating clip with transitions
Hi, i need to animate a variable sequence of poses in a character. I have an idle looping animations, and a bunch of other clips (each is a 10 frame non-looping static pose). My goal is to define a list of clips (not a problem) and them play them in this mode:
IDLE - TRANSITION - POSE01 - TRANSITION - POSE02 - TRANSITION - POSE03 - TRANSITION - IDLE
Also, i need to know the current animation name, to show it in a label. I tried with "CrossFadeQueued" and "PlayQueued", but i can't figure how to make it work.
Any idea? Thanks
Answer by 3DMedia Toonz · May 31, 2013 at 12:32 PM
Thanks, i'll try to use CrossFade, together with a yield function to wait for the end of clip:
function AnimateClips(){
myAnimation.CrossFadeQueued("idle", 0.1, QueueMode.CompleteOthers);
for(string animationName in myAnimationNames){
myAnimation.CrossFadeQueued(animationName, 0.1, QueueMode.CompleteOthers);
yield WaitForSeconds (myAnimation[animationName]].length);
}
myAnimation.CrossFadeQueued("idle", 0.1, QueueMode.CompleteOthers);
}
Answer by TonyLi · May 30, 2013 at 02:32 PM
You can use CrossFadeQueued or PlayQueued with QueueMode.CompleteOthers, which is the default. What's going on with your script? Something like this should work:
foreach (string animationName in myAnimationNames) {
animation.PlayQueued(animationName);
}
As for identifying the current animation: More than one animation can be playing at a time. For example, when you cross-fade, the first animation is playing and fading out, while the second animation is playing and fading in. During the cross-fade, Unity gradually decreases the weight of the first animation and increases the weight of the second.
So it's hard to say what the "current animation" is. You can loop through all the animations and choose the one with the highest current weight. For example:
string currentAnimation = null;
float highestWeight = 0;
foreach (AnimationState a in animation) {
if (a.weight > highestWeight) {
highestWeight = a.weight;
currentAnimation = a.name;
}
}
Your answer
Follow this Question
Related Questions
Copying Animation Clips from Imported FBX 1 Answer
"getcurve" from a gameobject 0 Answers
Queued animations 1 Answer
Record Animation Clip from changes made with Mesh API? 1 Answer