- Home /
Adding an eyeblink animation layer
Hi!
I have a character with some animations set up in Unity. Now I wanted to have another animation clip with random eyeblinks playing on top of the other animations. It is just a looping clip of about 300 frames.
I put this animation inside a new animation layer and set it to additive mode, it works well. But there is one animation clip in the Base layer where I don't want the blinks to show up.
How can I exclude this animation clip from the 'eye blink' layer so that the eyes won't blink when this certain clip is played?
I have made some screenshots to clarify my problem a bit:
So I want the eyeblink animation to loop continuously and keep adding eyeblinks to every animation clip in the base layer EXCEPT the one called 'Alien_LookUp_Smile_LookDown', because it already has specific face animation on it.
I wanted the eyeblinks on a different additive layer so that they would be more random and not dependent on the ti$$anonymous$$g of the other clips. This works fine, only I can't control on which clip the eyeblinks will be added or not.
$$anonymous$$aybe I'm approaching this the wrong way? Any help is welcome.
Answer by superpig · Jul 29, 2014 at 05:02 PM
The simplest way to do this is probably to just set things up so that the Weight of the eyeblinks layer gets brought to zero for the duration of the animation.
You could do this by simply changing the layer weight at the same time you set things to trigger the Alien animation to play, and then changing it again when you trigger progression to the next animation.
Alternatively, perhaps you could use Animation Events on the Alien animation to fire 'StopEyeBlinks' and 'StartEyeBlinks' events.
Thanks for the answer, superpig, it works for me. This is the code I put together if someone is wondering:
// Create an animator variable
private Animator anim;
void Start ()
{
//Grab the Animator component from the character
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
//Eyeblinking/////////////////////////////////////////////////
//Here we say when the Eyeblink animation should play or not//
//////////////////////////////////////////////////////////////
//check if animation lookUp has started.
//the (0) points to the Base Layer index, which contains the animation we want
if (anim.GetCurrentAnimatorStateInfo(0).IsName("Alien_LookUp_Smile_LookDown"))
{
//change the Eyeblink layer weight to 0, so no eyeblinks
//the first number stands for the layer index, so Base Layer = 0, Eyeblink Layer = 1
anim.SetLayerWeight(1,0);
}
else
{
//change the Eyeblink layer weight to 1
anim.SetLayerWeight(1,1);
}
}
The only thing it doesn't do is respect the transition to blend with the previous animation, which can sometimes still cause a bad eye deformation (2 eyeblinks on top of each other) when the transition blend hasn't finished yet and the Blink layer weight has already changed to 1.
But for now it's a good solution, thanks!
Your answer
Follow this Question
Related Questions
Possible to use different rig on layer mask? 0 Answers
Animation layers with Unity 2D mecanim 0 Answers
How to superimpose two animations using the animator? 0 Answers
Mecanim layers blending 0 Answers
Mecanim avatar masks don't work. 0 Answers