Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Dynamically masking upper body based on movement?

Discussion in 'Animation' started by Alpants, Oct 7, 2019.

  1. Alpants

    Alpants

    Joined:
    Mar 21, 2014
    Posts:
    4
    I am making an RPG style game. A lot of animation packages feature cool looking attack animations for sword swings and the like which involve the entire body moving, or at least the spine rotating.My game involves some stationary combat, with moments of moving around. Since I want to be able to attack while moving, I created a layer for "attacks" and masked off the upper body.

    Now all my attack animations look stiff and dorky, as you lose the cool full body motion and spine twisting. I guess I get the trade off, and for the most part while moving around players would be focusing more on the action than their own characters.

    To make things better, though, I would at least like to play the "full body" version of the animation as long as the character is stationary. However, it is always possible for the character to start moving "mid-swing". Is it possible to dynamically add/remove an upper body mask, even mid-animation?

    I tried playing around with a third "attack" layer with no mask, and using layer weights to control between the two but I couldn't even get the layers set up right. Is this possible and is there a better approach? Is my thinking flawed here?
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,486
    If you use Animancer (link in my signature) you can change the layer of an animation whenever you want. The Layers example demonstrates how you can have an action affect the whole body if you use it while standing or just the upper body if you use it while running.
     
  3. Alpants

    Alpants

    Joined:
    Mar 21, 2014
    Posts:
    4
    Thanks, I keep hearing about Animancer, I'll look into it. I'm hoping you can switch layers mid-animation.
     
  4. autumn_737

    autumn_737

    Joined:
    Jul 23, 2012
    Posts:
    18
    For anyone that needs to know I was able to get this to work using sync option in the layer settings.

    So first you have your Base Layer which would have Idle and Run.

    Then you have your Attack Layer that has your mask, eg: to attack while running. This should be able to blend with your run animation with its weight set to 1.

    Once that is set up, make a new layer and turn sync on and set sync layer to Attack Layer. The sync checkbox is in the layer's settings panel. We'll call this layer the Full Attack Layer and it will have no mask. It effectively creates an instance of the Attack Layer, which makes it identical in progression but without the mask so it overwrites the Base Layer.

    The next step is to track when your Character/Player is moving then set the Layer weight based on that:

    Character Moving:
    Attack Layer = 1
    Full Attack Layer = 0

    Character Standing Still:
    Attack Layer = 0
    Full Body Layer = 1

    It moves between the layers without a problem and you could go a step forward to smooth the weighting to get a softer transition between layers.


    I hope this helps someone out there!
     
  5. Big_Daddi

    Big_Daddi

    Joined:
    Mar 26, 2021
    Posts:
    1
    Wow, I've been struggling with this problem for years. Thank you so much! This solution works brilliantly with SetLayerWeight.