Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Attaching gun to hands?

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

  1. Doleman

    Doleman

    Joined:
    Aug 12, 2005
    Posts:
    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

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    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

    Joined:
    Oct 12, 2005
    Posts:
    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

    Joined:
    Aug 12, 2005
    Posts:
    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

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

    MetroidHunter

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

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    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

    Joined:
    Aug 27, 2005
    Posts:
    585
    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

    Joined:
    Oct 12, 2005
    Posts:
    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

    Joined:
    Aug 12, 2005
    Posts:
    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...




    Does this help? :p
     
  11. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    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

    Joined:
    Aug 27, 2005
    Posts:
    585
    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

    Joined:
    Oct 19, 2005
    Posts:
    1,351
    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?
     
  14. ItsJodo8

    ItsJodo8

    Joined:
    Jun 5, 2015
    Posts:
    1
    Idk Bro Sorry i came for the same question
     
  15. Wasiim

    Wasiim

    Joined:
    May 2, 2015
    Posts:
    228
    that is what she said. Sorry i had to.
     
  16. Frostbite23

    Frostbite23

    Joined:
    Mar 8, 2013
    Posts:
    458
    Lolololol, this thread is 8 years old.
     
  17. Wasiim

    Wasiim

    Joined:
    May 2, 2015
    Posts:
    228
    Well then, damn
     
  18. Megalodon7

    Megalodon7

    Joined:
    Mar 9, 2017
    Posts:
    1
    CandraWi and BurzumStride like this.