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

attach a two-handed weapon to a character

Discussion in 'Animation' started by Rubikpotato, May 25, 2015.

  1. Rubikpotato

    Rubikpotato

    Joined:
    Dec 25, 2014
    Posts:
    14
    Hi, I'm trapped on this overwhelming problem for quite a long time; I can't attach an AK-47 to the hands of my character and the same time make it sync with the arms animations. I'm working in a 3d game with a third person camera.
    Initially, I tried parenting the weapon to the hand bone in Unity, yet that seems to be very useful with one-handed weapons like pistols, but for a SMG it is very hard to synchronize the weapon rotation with the hands in the animations, if not it looks like the left hand is holding the air rather than the foregrip. Then I tried with joints. Those gave me a sort of the result I'm looking for, but then I noticed that in the animations the character's hands may have an exaggerated deform. Therefore I'd have to look out every 'frame' in order to be sure that those funny deforms were gone. So that is a big no-no if I have a lot of animations. The next thing I did was parent the weapon to the hand bone inside the 3D software (Blender), so in there I could sync the weapon with the animations very well. I thought that way I fixed the problem, but then when I re-imported the model (this time including the weapon), the ak-47 wasn't following the animations correctly like in Blender, it was just like in the beginning. It's just like Unity ignores what I've done in Blender.
    Anyone know how to solve this issue? Or rather the best way to attach the weapon to the character's hands without having to look out every frame?
     
  2. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Its pretty tricky.

    What I do is use Motionbuilder and parent gun to right hand (wrist effector during animation actually, then parent to bone towards end) and use a constraint to pull and lock the left hand to the weapon. then you have to make the left arm be fully influenced by IK, ie have no animation weight of its own. Then the left hand wrist effector is aligned right, bake the animation from the control rig to the bones, reparent the weapon from the control rig to the rh bone, then delete the control rig and its ready for unity.

    Unfortunately I am not aware of an easier way, but perhaps someone else has a suggestion. This is not particularly easy and may warrant hiring a Motionbuilder animator for this one particular animation.
     
    Aligdev likes this.
  3. Rubikpotato

    Rubikpotato

    Joined:
    Dec 25, 2014
    Posts:
    14
    Yea that seem very complicated to do just for one thing. I didn't really understand the process of what you said, but basically is give the left arm a ragdoll behaviour (free will of movement) and then "tie" it to the weapon? I got it right?
     
  4. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Yes thats the idea.
     
  5. pmurph03

    pmurph03

    Joined:
    Mar 17, 2014
    Posts:
    51
    I would go with the route of using attach points on each hand that the gun should be "attached" to, get the vector between those two points and orient the gun along that vector, while one if the hand as the constant point/pivot of the gun and with a proper orientation vector, then orient the gun along the vector between the hands using rotation. Or bake it into animations like you attempted to do using non humanoid animations and make sure both animations get played at the same time for the weapon and humanoid
     
  6. Jesse_Pixelsmith

    Jesse_Pixelsmith

    Joined:
    Nov 22, 2009
    Posts:
    295
    Might want to look into Final IK? They have something like hand effectors , pretty much the same principle but you don't need to get MotionBuilder involved. Need to know some code though.
     
  7. hopeful

    hopeful

    Joined:
    Nov 20, 2013
    Posts:
    5,628
    You might present this problem in the Bone Controller forum and see if there's an easy solution for it using BC. While I don't own Bone Controller (yet), I know it uses pseudo colliders, IK, and impact motors ... and it seems like you ought to have a solution with some mix of that.
     
  8. Rubikpotato

    Rubikpotato

    Joined:
    Dec 25, 2014
    Posts:
    14
    Sorry but, how I can do that?

    Even though I really want to, I have no money to buy assets to solve this, so for me using paid assets is a no-no. I don't really want to make the thing look fantastic, the only thing I want is to make it look like is really holding the gun and not the air, not necessarily to look realistic bc the camera is not so close to the player so basically you cannot see 'details'.
     
  9. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Hey @Rubikpotato you don't need any other software than what you already have.
    I'm not a blender user - but I know for certain blender has IK/FK constraints and blending.

    There are several ways to accomplish the result you want - check youtube - it doesn't have to be the same software as long as you can translate the lingo from whatever into blender logic.

    This is how I've accomplished this task in the past with two handed weapons.

    In 3D software (blender) align and parent a null object to the right hand bone.
    Parent the weapon to a null object.
    Position the weapon correctly so it is being gripped by the right hand. I usually do this by moving the weapon not the null, because if you want to switch weapons you want to keep the null in place.
    Create another null (weapon null) align this null to the weapon trigger grip. Exactly where the right hand is gripping the weapon.
    Parent the weapon null to the right hand null.
    Create a 3rd null object and position it where the left hand will be gripping the weapon.
    Parent this 3rd null to either the first null or to the right hand/wrist. (it doesn't matter which)
    Position the left hand onto the weapon - it should be perfectly aligned to the 3rd null object.
    IK constrain the left hand to the 3rd null.
    Animate the weapon position and orientation by animating the right hand/wrist. No animation keys on the weapon.
    The left hand will move accordingly and will remain locked onto the weapon.
    If needed - animate the swivel angle of the elbow so the left wrist looks accurate.
    When the time comes in the animation where the left hand needs to be removed from the weapon (changing a magazine, reloading, clearing a jammed round) animate the IK/FK blend from full IK to either full FK or animate the IK constraint from the null back to the IK solver. This will keep IK available to the animator, but will (turn off) the constraint to the weapon null.
    Animation done.

    Export the character, bones (armature), and nulls. Not the weapon. You may need to bake the bones to get the IK (this is not required in Max).
    Export the weapons separately so you can switch weapons later. If this is the only weapon used by the character - I think you can export the weapon with the character.

    In Unity if weapon was exported separately - re-parent and align the weapon back to the weapon null object as it was in 3D software (blender).
    Left hand now follows gun as intended.
     
  10. Rubikpotato

    Rubikpotato

    Joined:
    Dec 25, 2014
    Posts:
    14
    Thank you, I'll have your instructions in mind; in the time I didn't open the thread to check out if someone had replied, I kind of find my own way to solve this. What I did was to create this own bone for the weapon and "disconnect" it (no parent) of the rig.
     
    theANMATOR2b likes this.