Search Unity

Avatar Masks and Blending Layers

Discussion in 'Animation' started by Clydey2Times, Apr 21, 2019.

  1. Clydey2Times

    Clydey2Times

    Joined:
    Oct 24, 2017
    Posts:
    242
    Hey all. I'm new to avatar masks and I'm having an issue with switching between layers. Immediately going from a layer weight of 1 to 0 is causing my player character to snap back into an idle animation.

    Basically, when my player has a shotgun and is walking, I set the layer weight with the mask to 1. When the player isn't walking, I set it back to 0.

    I don't know the appropriate way to transition smoothly between layers. Any help would be appreciated. Here's the simple logic I'm currently using:

    Code (CSharp):
    1.  if(anim.GetBool("hasShotgun") && anim.GetBool("isWalking"))
    2.         {
    3.             anim.SetLayerWeight(1, 1);
    4.         }
    5.         else if(anim.GetBool("isWalking") == false)
    6.         {
    7.             anim.SetLayerWeight(1, 0);
    8.         }
    Should I decrement the layer weight gradually?
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    You might be interested in my Animancer plugin (link in my signature) which includes a function to fade layers over time. I have no idea why Mecanim doesn't have it built in. I've never actually tried fading layers over time when using Mecanim, but doing it manually could indeed do what you want.
     
  3. Clydey2Times

    Clydey2Times

    Joined:
    Oct 24, 2017
    Posts:
    242
    I might try that, thanks.