Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

How to use the Animation Rigging System for weapons?

Discussion in 'Animation Rigging' started by John_Leorid, Sep 23, 2019.

  1. John_Leorid


    Nov 5, 2012
    I've read the blog and watched the GDC talk about 10 times by now and I feel like I understand nothing.
    Put a Rig Builder here, a Rig there, add Constraints and you're done.. well, if it would be that easy..

    I am playing around with this for quite a while now and I guess 99% think of IK systems when they implement weapons on an enemy character which has to aim at the player or in TPS games, when they add weapons to the player character.

    Then there are some basic questions, where I haven't found an answer yet:
    1) Where to put the weapon? Usually it would be a child of a weapon bone, right? But the humanoid avatar does not have a weapon bone and we probably have about 5 rigged game characters and we want all of them to use weapons. None of them has a weapon bone or weapon animations. When we create it for one of them, we would have to add these bones to all of them. But still then, the weapon-bones are not linked and we'd need animations for all of them ..
    It would be nice to "parent" them to the chest (instead of an non existing weapon bone) without parenting them in the hierarchy, but creating some points (rifle socket, bazooka socket, pistol socket) which are outside the whole skeletton hierarchy.
    Something like:
    ---- ...
    ---rifle socket
    ----Assault Rifle
    ---pistol socket
    The "Weapons"-Transform moves and rotates with the chest of the character and all childs follow.

    2) How to setup the correct aiming? There is a multi-aim-constraint but it seems like another version of Transform.LookAt(); Lets say the weapon is soft-parented to the chest like in the example before, then the weapon should rotate around that chest, aiming at the targetTransform. Because just rotating the weapon itself won't help here.

    3) How to add the recoil? When a weapon is fired, it will move back a bit, the right shoulder will copy the movement of the gun to 50% and the weapon will aim slightly upwards, then everything goes smoothly back to the correct aiming state. Most probably my weapon socket would have this animation set up (or maybe it is scripted, so I can control the impact based on the weapon parameters)

    What is the suggested workflow to make humanoid characters hold (and use) weapons? (So that the weapon is stored seperately from the rig (if possible), aims correctly and recoil has an impact on the pose)
    Last edited: Sep 23, 2019
  2. Danila24ru


    Sep 21, 2012
    +1 !
    I am joining to the questions above.
    Why you did rig builder in parent (root). Does character model is replaceable?
    For example hierarchy that I Imagine should be:

    -player (root, rigBuilder, + my scripts)
    --model (animator) <-- Just replace prefab model of character
    ---- ....

    But now model must be 'root' and I can't change just model. I should setup all scripts and rigs for every character ?
    John_Leorid likes this.
  3. John_Leorid


    Nov 5, 2012
    Exactly, in my current setup (to play around) The "ShoulderWeapon Socket" is a child of the Shoulder Bone, Hands are placed with TwoBoneIK-Constraints to move with the weapon, the Socket itself has a Multi-Aim-Constraint to aim at the target, now I want the IK-Solver to move everything down to the plevis with the target, I tried every single constraint and if it doesn't create something creepy (completely broken spine with the chain IK for example) the aim will be wrong (e.g. using the Multi-Rotation-Constraint will bend bones after the aiming happend and as the weapon is a child of those bended bones, it will ruin the aiming). So basically I'd need some sort of Chain-IK-Constraint combined with the multi-aim-constraint?

  4. John_Leorid


    Nov 5, 2012
    Nevermind the chain-thing, I am pretty sure it would be possible if I just add an aim-constraint to every bone I want to move with the target (with a small weight).
    Recoil is also quite fine, as the TwoBoneIK for the arms works perfectly fine.
    Biggest Problem by now is, as @Danila24ru mentioned the hierarchy and that the system does not work with avatar masks.
    I have two layers, BaseLayer and UpperBody in my Animator and I can only control the upper body with IK (again I tried all constraints). I tried to use the TwoBoneIK for the feet but this only works when I switch the animator to one without a masked second layer.
    Why does the system only work when the model is a root gameObject (it can be parented at runtime without issues, so it has to do with loading the data I guess?).
    Why does it not work with Masked (override) Layers on the animator?
    Why must every Rig be a child of the Model containing the Rigbuilder&Animator?

    Will this change in the future?
  5. simonbz


    Unity Technologies

    Sep 28, 2015
    Hi, Let me try and answer some of your questions

    This is a known issue and is being looked at right now. You can follow up on the progress here:

    It should. AnimationRigging processes the Animator output. Avatar Masks are only relevant in the state machine.
    I think you are using a humanoid character in your project right? Is this working with a generic character? This works in our setup for humanoid and generic. Do you mind submitting a bug report so we can have a deeper look at your setup?

    AnimationRigging works as a post-process step of the Animator and has the same restrictions as any animated hierarchy. The Animator can only animate properties in its own hierarchy and thus, AnimationRigging must follow the same restriction.
  6. John_Leorid


    Nov 5, 2012
    Thanks for your answers, I'll try to submit a bug report.