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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Mecanim humanoid rig with weapon?

Discussion in 'Editor & General Support' started by Waliactico, Aug 5, 2013.

  1. Waliactico

    Waliactico

    Joined:
    Jan 16, 2013
    Posts:
    91
    Hi, I have a character who uses 2 kind of weapons (a gun and a shotgun), therefore that weapons have its own animation so they can be on the character's hand, or holded on his back.
    My question is, is there any way that I could configure a humanoid rig in unity and still use that weapons? I suspect that I must use a generic rig with the skeleton+weapons, but it would be better if I could use a humanoid one.

    Thanks in advance!
     
  2. Waliactico

    Waliactico

    Joined:
    Jan 16, 2013
    Posts:
    91
    anyone?
     
  3. porglezomp

    porglezomp

    Joined:
    Aug 21, 2012
    Posts:
    40
    Could you have the weapons parented to the humanoid rig? That way they're a separate rig that moves along with the humanoid one.
     
  4. Waliactico

    Waliactico

    Joined:
    Jan 16, 2013
    Posts:
    91
    hmm I think it could be done that way, but then the weapons would need its own animator controller (though it would be the same as the humanoid, but just another one), so changes would be a little painful. I think I'm going to make it a generic rig, with the weapons in the same rig as the human, since it appears that a humanoid rig is not allowed to have extra joints of any kind
     
  5. XGundam05

    XGundam05

    Joined:
    Mar 29, 2012
    Posts:
    473
    Usually, I believe this is done by parenting the weapon (a separate model) to the bone in the rig that it will be "attached" to. So, for instance, a sword that is being held would be parented to the hand. The sword itself doesn't have any animations, just the humanoid rig. Then the sword would move with the hand.
     
  6. Waliactico

    Waliactico

    Joined:
    Jan 16, 2013
    Posts:
    91
    yes, that's when the sword is always held, but this is no the case. The character can pick up a weapon, leave it held on its bac, pick up another one, and so on, so the weapons need to have their animations, at least to have its constrain to the hand on and off
     
  7. XGundam05

    XGundam05

    Joined:
    Mar 29, 2012
    Posts:
    473
    So you attach the weapon to the spine. What animations do the weapons have? Firing mechanisms can be played simply on the weapon, and recoil should be done on the humanoid.

    Example:
    So, you have a weapon on the ground.
    1) Character plays "bend down/pickup" animation
    2) using animation curves, trigger event to attach (parent) gun to hand (there's info somewhere about doing this with Mecanim)
    3) Player decides to holster weapon
    4) Character plays "holster" animation
    5) using animation curves, trigger event to attach (parent) gun to holster position
     
  8. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,171
    You wouldn't attach the weapon to the spine normally. Normally you would attach it to the hand that is wielding it, so it plays along with the current animation.
     
  9. XGundam05

    XGundam05

    Joined:
    Mar 29, 2012
    Posts:
    473
    The idea is you attach it to the spine when it's holstered on the back. Or to the hips, or wherever it would be holstered/sheathed. Otherwise, (as said in a previous post) you would indeed parent it to the hand for animation purposes.
     
  10. Waliactico

    Waliactico

    Joined:
    Jan 16, 2013
    Posts:
    91
    Ahá, I see. The thing is, the weapons are currently a revolver and a shotgun. I think the revolver could use that strategy easily, but maybe with the shotgun it's not possible, since it's a long weapon that has to be used with both hands, making it mandatory to adjust it to each hand according to animation.
     
  11. porglezomp

    porglezomp

    Joined:
    Aug 21, 2012
    Posts:
    40
    You'd have to have the hands match up anyway, even if they were in the same skeleton. I don't think it makes editing that much harder.
     
  12. XGundam05

    XGundam05

    Joined:
    Mar 29, 2012
    Posts:
    473
    This is not an insurmountable problem. How do you think games like Borderlands, with it's procedurally generate guns, do it? As porglezomp said, no matter what the animation has to line up with the weapon.

    Example procedure:
    1) Model character
    2) Model shotgun
    3) Bone character with shotgun (parenting the shotgun vertices to the same bone you would in the game)
    4) Animate character with shotgun
    5) Remove shotgun from character model
    6) Use in game
     
  13. Waliactico

    Waliactico

    Joined:
    Jan 16, 2013
    Posts:
    91
    I think I'm not understanding it well. What you are saying is that the shotgun is controlled directly through the hand transform (since it should be its parent when shooting), right? So that any position/rotation of the shotgun will be actually the position/rotation of the right hand bone. Did I get it right?
     
  14. XGundam05

    XGundam05

    Joined:
    Mar 29, 2012
    Posts:
    473
    Correct, it's very similar to how it works in real life.
     
  15. Waliactico

    Waliactico

    Joined:
    Jan 16, 2013
    Posts:
    91
    Thank you all, I will try that. I hope that already made animations will fit to weapons placed this way!
     
  16. shaimon

    shaimon

    Joined:
    Aug 13, 2012
    Posts:
    2
  17. mnierkr

    mnierkr

    Joined:
    Oct 11, 2014
    Posts:
    2
    All you have to do is not map bones on the hand and just model the way you want it. This way the non-mapped hand(fingers) won't be affected by the mecanim animation.
     
  18. rorylane

    rorylane

    Joined:
    Apr 10, 2013
    Posts:
    22
    Mecanim humanoid doesn't delete your extra bones, but it won't include extra bones in your animation files unless you include them in the Mask->Transform settings of the rig your extracting the animation from.
     
    vahidsn likes this.