Search Unity

Animation Layer Weapon System FeedBack? :)

Discussion in 'Animation' started by DouglasPotesta, Jul 18, 2017.

  1. DouglasPotesta

    DouglasPotesta

    Joined:
    Nov 6, 2014
    Posts:
    109
    Hi guys. I am experimenting with some animation layers for a weapon switching mechanic and I would like some feedback on the methodology. My main concern is that I may be doing this the hard way right now and wanted to know if anyone had better ideas for handling weapon switching. All feedback really is appreciated.

    ;)

    So the way I currently have my animations set up is I use several layers on the character.​

    upload_2017-7-17_21-11-40.png

    The Rifle and Pistol all sync with the Base layer and currently on have influence over the upper body. Based on which weapon the player is using, the layers will play a weapon switching animation, and then change the weight of the layers to match which weapon they are using.

    This behavior only works for weapons that have similar animation behavior, and I wanted to know if you guys had any recommendations for doing this differently. The base layer has a lot of sub state machines so I'd prefer not to resort to creating several Sub State Machines for different weapons if possible.

    Base State Machine:

    upload_2017-7-17_21-7-43.png

    Base Layer > Standing
    upload_2017-7-17_21-9-36.png

    Base Layer > Ground
    upload_2017-7-17_21-10-45.png



    I've never made a full featured combat system like this before, so I'm really trying to learn from this. Any advice, comments or Feedback is greatly appreciated.
     

    Attached Files:

  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Ive not created such a complex animation state machine - so far - so Im just going to post my initial thoughts on your images and end goal.
    I always think the base layer should be the bottom layer while additive or override layers are above the base. I might be mistaken/backwards, jumping from Unity to photoshop to mudbox to after effects to avid scrambles the memory a little.

    Are the rifle/pistol layers set to additive or override?

    When you mention behaviors of similar weapons, are you talking about similar rifles working alright with this set up and similar hand guns working alright, but having a rifle and pistol (because there behavior is different) doesnt work correct for this set up?
     
  3. DouglasPotesta

    DouglasPotesta

    Joined:
    Nov 6, 2014
    Posts:
    109
    Hahaha. Yeah that happens to me sometimes as well. In unity the top layer in the stack is the most base layer.

    They are set to override. They are masked so they only affect the upper body though.

    Yeah so because the layers are synced they always share the same animation logic. So any weapon that works similarly works fine, I can just swap out some animations. However, if I wanted a weapon like a knife or a baseballbat, then I couldn't just swap out the animations. The logic doesn't line up well.

    Example:

    The player will aim a pistol and take as long as they need to line up a shot. If it was a baseball bat, i would want the player to use the aim button as an alternate attack instead of aiming, and I would want them to be able to combo between different animations.

    Now I could just dumb down the baseball bat mechanic, and literally have the player aim where they want to hit and then "shoot" making them swing the bat. However this doesn't give the baseball bat the distinct feel it should have.

    I guess in explaining it. I realize I can't use a sync layer for the baseball bat idea, but instead I'll have to make a new substate machine for Merle based weapons.

    Thank you for your reply.

    I'm still open to more feedback on this idea btw. If anyone thinks that there is a better way please let me know. ;)
     
    theANMATOR2b likes this.
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    TonyLi has detailed a couple animation state machines where he swaps the state machine based on the weapon use. I've never done this type of complex set up before - and it seems like how he set it up really performed well, but to me it seemed very complex. I think if I was able to get ahold of a system like that and see how it was set up I would get a better understanding of it.

    Anyway - might look back through his post history to see the references to this type of setup.
     
    DouglasPotesta likes this.
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    This is exactly what sync layers are made to do, so you're definitely doing the correct thing from a design point of view.

    The only thing I wonder about is how you handle switching between weapons. Do you play the holster animation, wait until it's finished, switch which layer's active, and then play the pull-out-weapon animation?
     
    theANMATOR2b and DouglasPotesta like this.
  6. DDNA

    DDNA

    Joined:
    Oct 15, 2013
    Posts:
    116
    I just got done making a system like this, each weapon had about 30 animations. What I did was very similar except I only had one layer for the weapons and used the override controller. That way I could have only one state graph and have a scipt that sets the override controller up for all weapons.

    What sucks about the synced layer is that it doesn't sync blend trees and the copy and paste across layers doesn't work in Mechanim (you end up with linked references it is bizarre) so there is a lot of drag and drop and re setting up of things.
     
  7. DouglasPotesta

    DouglasPotesta

    Joined:
    Nov 6, 2014
    Posts:
    109
    Thanks for the lead on tonyli. He's got a lot of useful information. I'll probably rework a lot of other aspects of my animator using Animator.CrossFade() for some of the more complex stuff.

    I haven't implemented a switch animation yet, but planned to have the layers use a switch out animation->Change The weight to the proper weapon -> then switch in animation

    Hmm odd. My animations act perfectly fine with the synced layers. I only place them where the behavior is intended to be different. So for example the locomotion, the aiming, the shooting. But stuff like jumping, or diving, rolling don't require me to place animations on them again.


    I want to thank all of you guys for the helpful posts. It really is nice having a second set of technical eyes on this. I don't know anyone IRL who has dealt with complicated animation trees like this before, so your feedback is mega helpful.
     
  8. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
    Hello @DouglasPotesta,
    I have the exactly same need for my TPS game. Currently, we are using the Animator Controller from UFPS with some modification (since we mainly use Third Person camera). It uses sub-states for each (type of) weapon.
    Then I found another solution from Kubold's animation sets. He uses the same states but switches the animations by a blend tree based on the "Weapon Selection" bool parameter.
    UFPS:
    UFPS_Arm.jpg Arms

    UFPS_Arm2.jpg Arms for one weapon

    UFPS_LB.jpg

    Base layer
    KUBOLD
    Kubold_Base.jpg Base layer

    Kubold_Base2.jpg One state with blend tree for different weapons

    So I'd like to ask for the advice: which solution feed our need, an online TPS game which player can equipd several weapons and switch between them during a match.

    Thanks,
    Anh
     
  9. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
    Switching weapon layer from Kubold.
    Kubold_SwitchWeapon.jpg
     
  10. DouglasPotesta

    DouglasPotesta

    Joined:
    Nov 6, 2014
    Posts:
    109

    Hmmm well Kubold is a third person shooter animator, and UFPS is a first person shooter system.
    You said you were making a TPS, third person shooter.
    UFPS is not third person.
    Kubold is third person.
    Between the two, I'd recommend Kubold

    If I am being honest though, you will probably still struggle with Kubold. If you are using the one that comes with helper scripts and stuff, then that would totally help.
    Now I've never used Kubold or TPS, I just watched the tutorials on how to use them.
     
  11. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
    Actually, we need a starter solution to reduce the initial workload. So we picked UFPS to utilize current features (they support 3rd person as well).
    What I'd like to ask is the better solution for Animator approach (layer, switching weapon)
     
  12. Vazili_KZ

    Vazili_KZ

    Joined:
    Sep 18, 2016
    Posts:
    25
    Hi guys,

    i'm in the same situation right now and If i may i'd like to ask you which approche did you end up choosing?

    @DDNA This looks quite interesting, combining the power of Layers with the Animator Override Controller, but unfortunatly i don't see how this could be implemented... If you could provide some more details on this approach that would be awesome.

    @DouglasPotesta I'd also like to know if you found a better solution for the Melee Weapon Attack or did you just end up taking the "New SSM" approach.

    @LeGiangAnh Between the UFPS & Kubolt which did you end up using?

    In my humble opinion i think that the UFPS animator is better structured. It's true that using different SSM for each weapon type will make us end up with a repetitive Animation tree inside every SSM but nevertheless it's still more clean and easily expendable.

    i'm really looking forward to hear your feedback guys. i know this post is old but i'm hoping this will be an advantage since there is a great chance every one of you has managed to solve it his own way and hearing you experience with this subject will be very instructive.
     
  13. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
    @Vazili_KZ we used Kubold's approach. Trust me, using SSM for every weapon is a nightmare.
    Anyways, there should be a better approach with Animator Override Controller but I haven't tried it yet. Feel free to post your solution after doing your research.
     
  14. Vazili_KZ

    Vazili_KZ

    Joined:
    Sep 18, 2016
    Posts:
    25
    @LeGiangAnh Thank for the reply man.

    I started trying this approach these last couple of hours and it's indeed a nightmare haha.

    I've already ran into several problems for ex : i'm trying to figure out how to use Animator.CossFade to go directly into a SSM rather then a specific state. So far no luck trying to achieve this and i haven't found anything in the forums neither.



    I could use the Empty State to check for a 'WeaponType' int and create transitions to every weapon but i really want to avoid the extra transitions so that i don't end up with a "Spaghetti" Animator...
     
    MetaDOS likes this.
  15. MetaDOS

    MetaDOS

    Joined:
    Nov 10, 2013
    Posts:
    157
    Yeah that's why I posted here for the advice. I think Unity should have some best practices for such as this case since it is popular. Maybe you should tag someone from Unity for their advice.
     
    DouglasPotesta likes this.
  16. Vazili_KZ

    Vazili_KZ

    Joined:
    Sep 18, 2016
    Posts:
    25
    Indeed i think that's the best thing to do here since i've searched the forums i found people having a similar issue but non provided a solution.
    This is a thread that discussed this subject and the @Mecanim-Dev were in the conversation but the thread was dropped without updating if this issue has been fixed or not.

    maybe the @Mecanim-Dev can help us shed some light into this if they're kind enough to reply.
     
    DouglasPotesta likes this.
  17. DouglasPotesta

    DouglasPotesta

    Joined:
    Nov 6, 2014
    Posts:
    109
    Unity’s animation system is a bit lacking in the visual logic power. I ended up using various systems over the past few years.
    There are compromises that come with each method.
    1) Using layer style weapon types leaves you with identical behavior between weapons but different animations. Useful for reusing animation behavior across different weapons.
    2) Using SSM per weapon provides massive flexibility at the cost of logical complexity. It is difficult to maintain common functionality across weapons without a lot of reimplementing the same thing many times.
    3) Using SSM per state behavior, is similar to two but maintains a little more reusablilty across weapons.
    BaseBehaviorStateMachine->attack_SSM->pistol_attack_SSM.
     
    Vazili_KZ likes this.
  18. Vazili_KZ

    Vazili_KZ

    Joined:
    Sep 18, 2016
    Posts:
    25
    @DouglasPotesta Thanks for your reply man.

    Thanks for sharing your experience that's some very valuable information that could save someone hours of trying the wrong approach and then starting over.

    As for my case i ended up using a Hybride of Synced Layers and Animator Override Controllers and it seems to work perfectly.

    It allows to maintain common functionality across weapons (That are supposed to have a commun behavior of course)
    And also it's very clean... the sweet spot ;)

    I have't found the downsides for this approach yet, since i'm not facing any problems for now... If i do, i'll make sure to update this thread.

    I will post a detailed explanation on how i achieved this later today, this way if someone in the future faces the same problem hopefully this will help.

    Thanks again to all of you guys you've been very helpful.
     
    DouglasPotesta likes this.
  19. Vazili_KZ

    Vazili_KZ

    Joined:
    Sep 18, 2016
    Posts:
    25
    So as promised here is how i implemented my Synced Layers & Animator Override Controllers Hybride :

    The Animator Structure :

    First let me start with a screenshot of the Animator :


    For the purpose of this thread we will focus on these 3 Layers :


    As you can see in the first picture the Base Layer contains the Locomotion SM. It's for the Unarmed Movements.

    The other two layers "Armed Relaxed" & "Armed Aim" are Synced with the Base Layer (explained shorty they are exactly a copy of the Base Layer expect the animations clips can change. You can find more details about Animation Layer syncing here.)

    - the "Armed Relaxed" layer contains animations where the player has a weapon in his hand but he's not shooting
    - the "Armed Aim" Layer contains animations where the player is actually shooting/aiming.

    Here are picture of the player when each one of those layer in applied :


    Base Layer / Armed Relaxed Layer / Armed Aim Layer​

    Animator Override Controller :

    So far, all this works perfectly if we have only one weapon. If we want to have different animations for different weapons that's when the Animator Override controller comes into play.

    We will create one for every weapon and replace the animations that are used in both the "Armed Relaxed" & "Armed Aim" Layers with the new weapon's animations.

    You can learn more about the Animator Override Controller and how to create and setup one Here.

    Changing the Animator on Runtime:

    Now to change the animator on runtime you need this code :

    Code (CSharp):
    1.     [SerializeField] private RuntimeAnimatorController[] overrideAnimators;
    2.  
    3.     private void UpdatePlayerAnimator()
    4.     {
    5.         if (!EquippedWeapon) return; // Check first if we have a weapon equipped
    6.         // Getting the EquippedWeapon's ID
    7.         var _WeaponId = EquippedWeapon.GetComponent<FireWeapon>().itemId;
    8.         //Set the WeaponType in the Animator
    9.         _playerAnimator.SetInteger("WeaponType", _WeaponId);
    10.         //Overriding the Animator
    11.         _playerAnimator.runtimeAnimatorController = overrideAnimators[_WeaponId-1];
    12.     }
    Now of course the code will vary depending on how you setup your weapons system and the names ofyour variables but you get the idea.

    In the inspector we will get this :


    - The Size will be the number of weapons your player has.
    - Each element will contain the Animator Override controller specific to each weapon.
    Of course you need an ID for each weapon to know which Animator Override to apply.

    This is it. Now you cant switch between different weapons and have their specific animations plays

    This example shows only Locomotion, you can apply this approach to all different SMs (Shooting/Vaulting/Cover...etc)
     
    DouglasPotesta likes this.
  20. secondstreet

    secondstreet

    Joined:
    May 21, 2017
    Posts:
    5
    @Vazili_KZ Thanks for posting your details! I just started experimenting with how I would organize animations for an FPS, and as a first step I created an Animator with one layer that could potentially be used as the base for other layers (see attached screenshots). The zoomed-in image represents forward movement. In the wider image, the other parts are basically identical to forward movement, with the other branches representing animation blends for Idle, Move Backwards, Move Sideways Left, and Move Sideways Right. For clarity, I adopted a naming convention to distinguish nodes more clearly: st - a single state, bt - blend tree, tr - transitional animation between two nodes.

    Do you think your approach could be adapted to my starting setup, just with different layering criteria? I started setting it up this way because if I'm using Mixamo animations, I wasn't sure how effective it would be layering by body area to take advantage of masking since simple changes like from walking to running, or from walking holding a rifle to walking aiming a rifle seem to involve whole body changes, not just lower body or upper body. Or, since I'm new to this, maybe I'm just not understanding it in general. o_O

    UnityBlendMapsForMovementForward.png UnityBlendMapsForMovement.png