Attaching gun to hands?

Discussion in 'Scripting' started by Doleman, Aug 8, 2007.

  1. Doleman

    Doleman

    New Member

    Joined:
    Aug 12, 2005
    Messages:
    87
    Hi (again)! :)

    I have a somewhat basic question I guess, but how can I make a gun stick to the hands of my character?
    Is this setup in the 3Dapp (Im using Cheetah3D) or in Unity?

    I'm trying to get the arm of the char to hold the weapon and then when I move the weapon the arms should "just follow" if you know what I mean...

    But right now I can't even attach the gun, does someone have any input on how to do this?

    // Big bad newbie ;)
  2. AaronC

    AaronC

    Member

    Joined:
    Mar 6, 2006
    Messages:
    3,215
    Hi
    The fps tutorial ones are positioned in the scene and then parented to the camera...

    Drag gun onto camera in hieracy

    Does that help?
    Cheers
    AC
  3. jeremyace

    jeremyace

    New Member

    Joined:
    Oct 12, 2005
    Messages:
    1,661
    I have never done it in Unity, but basically what you want to do is parent the transform of the gun to the hand bone in your character's skeleton. Simply positioning them and parenting should work, but it may take a bit of tweaking to get it to look right.

    -Jeremy
  4. Doleman

    Doleman

    New Member

    Joined:
    Aug 12, 2005
    Messages:
    87
    Thanks, my gun is positioned like it should now :)

    But 2 questions:

    1. How can i make the character hold the gun with both hands? I can only get him to have it as as child to one of them...

    2. How can I make the arms follow the gun and not the other way around (as it is now...)

    Thanks in advance ;)
  5. redghost

    redghost

    New Member

    Joined:
    Mar 7, 2007
    Messages:
    82
    You can put another gun to the other hand. it will be sooo cool!!! :p
  6. MetroidHunter

    MetroidHunter

    New Member

    Joined:
    May 22, 2007
    Messages:
    213
    And then make them pistols! :p
  7. jeremyace

    jeremyace

    New Member

    Joined:
    Oct 12, 2005
    Messages:
    1,661
    To get the other hand on might be tricky actually. You might actually need IK code to do that, which isn't the easiest thing to do, but it's not too bad.

    Perhaps someone has a better idea than IK?

    -Jeremy
  8. GusM

    GusM

    Member

    Joined:
    Aug 27, 2005
    Messages:
    570
    Make an animation of the character with the two hands together, using IK in your animation app. Then parent the gun to one of the hands, inside Unity. That would be the usual aproach AFAIK.
  9. jeremyace

    jeremyace

    New Member

    Joined:
    Oct 12, 2005
    Messages:
    1,661
    That of course would work if he can break it down to a few animations, but I got the impression that he wanted non-canned movement.

    Doleman: If you can fake it with animations, I also recommend that you do so.

    -Jeremy
  10. Doleman

    Doleman

    New Member

    Joined:
    Aug 12, 2005
    Messages:
    87
    Ok, I've made a very ugly image on what I'm trying to achieve here
    I'm the programmer, not the artist ;)

    The cross on the picture is supposed to be the mousepointer, and the gun is aiming at the cross all the time.
    The hands are just supposed to "hang on" to the gun when it changes direction...


    [​IMG]

    Does this help? :p
  11. bigkahuna

    bigkahuna

    Member

    Joined:
    Apr 30, 2006
    Messages:
    5,420
    You might be able to achieve this with physics joints at the shoulder and elbow of the character and then move/rotate the forearm/hand/gun to align with the shooting angle. The result may not be very natural looking.

    Naw, second thought, that probably wouldn't work.

    Another idea might be to create an animation that goes from "gun aimed high" to "gun aimed low" and play the animation to a particular frame based on the angle to the target.

    Not exactly sure how these would be done, but should be possible...
  12. GusM

    GusM

    Member

    Joined:
    Aug 27, 2005
    Messages:
    570
    Yes, this is usually built with IK (inverse kinematic) inside the modelling-animating app. of your choice. Cheetah has good IK. Look for the videotuto of the rigged arm and you will understand it better. With this tool you can use a separate bone as the "driver" for the arms chains, just like in your example.

    I would build (in cheetah) an animation with the vertical movement between two extreme poses (looking up and looking down) and then another animation with the horizontal movement.

    Then, in Unity, you will need to build a script interpolating those two animations to be used with the horizontal and vertical input axes. And, of course, attach the gun to the same bone used as an IK target in your animations. But I cannot help you in this, as I am only an artist, not a coder ;)
  13. drJones

    drJones

    Member

    Joined:
    Oct 19, 2005
    Messages:
    1,352
    i have a project with a similar control idea on the back burner atm that was kinda my thought as well. for an FPS view anyway i imagine you can have two arms that are separate jointed objects parented to a master object (for character movement rotation). the gun arm gun does the lookat is clamped to a max angle - the hand on the other is jointed to the gun. never got around to trying it though - but wouldn't that work?