Search Unity

Not sure on how to use Layers and AvatarMasks in this case?

Discussion in 'Animation' started by Milionario, Oct 16, 2020.

  1. Milionario

    Milionario

    Joined:
    Feb 21, 2014
    Posts:
    138
    I have a character that when hit, would act in one of a lot of ways.

    For example he could be hit directly in front and play one of 3 animations based on impact force.
    Now you can see where this is going.

    He can be hit in the front, back, sides, diagonally and so on.

    Some animations only need upperbody motion because the impact force is not big. For example when he is hit on the shoulder with low force only his upper body would sway a bit, if impact force is higher his lower body would move too.

    So I researched about Animator Layers and Avatar Masks, but still not quite getting it how I would put this all together, we could be talking about 30+ animations.

    The only thing I know how to do now is to have all separate animations and switch on the triggers by script, my impact detection script would be responsible to figure out which trigger to set based on the impact direction and force.

    But that doesn't seem optimal, Im gonna end up with a huge spaghetti animator
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    You can use animator.CrossFade to transition to any animation without needing to set up parameters and transitions in the Animator Controller, but you're still going to end up with a huge mess with that many animations.

    You might also be interested in Animancer (link in my signature) which lets you avoid Animator Controllers entirely to play and control all your animations directly in code.
     
  3. Milionario

    Milionario

    Joined:
    Feb 21, 2014
    Posts:
    138
    I like the way your solution works so far. I am testing the LITE to see if it will suit my needs.

    Do you know if standard unity animator can play animation in layers like your do, it looks like you can literally make a call to play an animation in a layer with Animancer
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Animator Controllers have layers that serve a similar purpose, but you have to set them up beforehand and your scripts have to know which layer you put each state on, you can't just tell it what you want to play and on which layer like you can with Animancer.
     
  5. Milionario

    Milionario

    Joined:
    Feb 21, 2014
    Posts:
    138
    Could Animancer help me avoid the huge clutter of animations? I mean I still gonna have lots of them
     
  6. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    You'll still have lots of animations, but you can properly organise them in a way that makes sense instead of just sticking them all in one big Animator Controller. Even if you end up with a script that manages getting hit which has references to 30 different animations, you are still keeping those animations separate from all the character's other animations.
     
  7. Milionario

    Milionario

    Joined:
    Feb 21, 2014
    Posts:
    138
    In this using animancer it would be different than using animator.CrossFade because you still gotta have all the states in the animator? I mean they would be there doing nothing in unity's animator
     
  8. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I'm not really sure what you're asking.

    Animancer doesn't require an Animator Controller at all. You just give your script a reference to an AnimationClip then call animancer.Play(clip) so you can organise your clip references however you want.
     
  9. Milionario

    Milionario

    Joined:
    Feb 21, 2014
    Posts:
    138
    I meant that if i use unity's standard animator controller with the CrossFade method, I would still need these states in the animator graph as opposed to your solution where I would only need to reference AnimationClips in a script and call animancer.Play() on them, is that correct?
     
  10. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Yeah, that's right. That's actually how I was using Animator Controllers before I made Animancer. Just states with Exit Time transitions back to Idle but no other parameters or transitions. It works, but it's not a good workflow.