Search Unity

Need help with FPS arms!

Discussion in 'General Discussion' started by Hinkel, Feb 19, 2017.

  1. Hinkel

    Hinkel

    Joined:
    Feb 19, 2017
    Posts:
    9
    Hey, after searching the whole internet and testing things out about 3 weeks I still can't figure out how FPS hands with the gun attached to them are made. Do you:

    1. Only use the hands in unity and use IK targets to get the right position for different guns? If yes, how would you make reload animations?

    2. Use guns with arms attached? If yes, would you need to change the texture of all guns/arms if you want to implement for example clothing?

    3. Only use one pair of hands with many animations for every gun and then attach the active gun to a bone? How would you make reload animations in that case?

    4. Use a completely different way?

    Really need help on this one since I can't go on with the development of my game :(
    And Sorry for my terrible English!

    Yours faithfully Smurf
     
    sas67uss likes this.
  2. N1warhead

    N1warhead

    Joined:
    Mar 12, 2014
    Posts:
    3,884
    I've always just either A) Put an empty game object in the palm of the hand and make it a child of the hand bone. or B) make the weapon a child of the hand bone.
     
  3. Hinkel

    Hinkel

    Joined:
    Feb 19, 2017
    Posts:
    9
    Hmm.. but how did you make reload animations then?
     
  4. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,569
    In animation clip, add some sort of animation event and swap guns when event is triggered. IK chains are probably are a bad idea and will look awkward.

    [
    This can work, and this is the easiest way. To change clothing you can change mesh or material on the mesh at runtime.

    This can also work. Reloading animations will be done with animation events.

    Can't think of any other way. I think you listed all or most of them.

    https://docs.unity3d.com/Manual/animeditor-AnimationEvents.html

    Make an event for a moment when weapon changes, when clip is being detached, then hide/show/swap objects on the runtime when the event is received.

    Having said that, you only need animation events to handle weapon reloading with moving parts/detachable clips. Switching weapons does not require animation events.
     
  5. Hinkel

    Hinkel

    Joined:
    Feb 19, 2017
    Posts:
    9
    Thank you very much! I'll try that out.
     
  6. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    I have a script that matches bone names and then parents and positions them. This way, as long as the clothes were made for the figure (in this case, the arms) and you didn't change the bone names, you can simply "conform" the clothes to the arms. I got the idea from Poser and a ragdoll tutorial I watched. This way you only need one set of arms with animations and can have unlimited number of clothes. If you turn off the renderer on the original arms, you can even replace them completely with ease.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ClothesParenter : MonoBehaviour {
    5.     public Transform[] bones;
    6.     public Transform[] parentBones;
    7.     public GameObject parentHip;
    8.     public GameObject myHip;
    9.     private bool matched=false;
    10.  
    11.     void Awake()
    12.     {
    13.  
    14.  
    15.     }
    16.     void Update () {
    17.         if(matched)return;
    18.          if(parentHip==null)
    19.         {
    20.           parentHip =transform.parent.GetComponentInChildren<MyHip>().gameObject;
    21.          //create a blank script called "MyHip" and attach to root of bones
    22.             return;
    23.  
    24.         }
    25.         if (myHip == null)
    26.         {
    27.  
    28.             myHip = GetComponentInChildren<MyHip>().gameObject;
    29.             return;
    30.  
    31.         }
    32.         if (matched==false)MatchChildrenTransform();
    33.     }
    34.     void MatchChildrenTransform()
    35.     {
    36.         matched=true;
    37.         bones=myHip.GetComponentsInChildren<Transform>();
    38.         parentBones=parentHip.GetComponentsInChildren<Transform>();
    39.         foreach (Transform trans in bones)
    40.         {
    41.             foreach (Transform trans2 in parentBones)
    42.             {
    43.                 if(trans.name==trans2.name)
    44.                 {
    45.                     trans.parent=trans2;
    46.                     trans.position=trans2.position;
    47.                     trans.rotation=trans2.rotation;
    48.                 }
    49.             }
    50.         }
    51.     }
    52.     // Update is called once per frame
    53.  
    54. }
     
    Last edited: Feb 19, 2017
    theANMATOR2b likes this.
  7. Hinkel

    Hinkel

    Joined:
    Feb 19, 2017
    Posts:
    9
    Great idea! Thank you!
     
  8. Hinkel

    Hinkel

    Joined:
    Feb 19, 2017
    Posts:
    9
    I wonder how Nelson Sexton did this in Unturned. Because there you even can make custom guns and stuff for the game and the hands are always perfectly positioned without having any IK targets. Any ideas how that's done?
     
  9. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    If you want perfection, you can always build a custom set of animations for every gun. Considering how few unique guns a FPS normally has, and how much screen time guns get, building custom isn't a bad way to go.
     
  10. Blacklight

    Blacklight

    Joined:
    Dec 6, 2009
    Posts:
    1,241
    I usually just rig the gun and hands in Blender for each weapon. You can use the same hand model for each weapon, it's just going to need different animations.

    For something that's going to be right in the player's face for most of the game, it's worth putting in extra time and resources.
     
    Kiwasi likes this.
  11. Hinkel

    Hinkel

    Joined:
    Feb 19, 2017
    Posts:
    9
    Thanks for all of your replies! I've tried out almost everything now but I still ain't really satisfied with any of the solutions :(. I, for example, want the users to be able to create custom guns and stuff but then I realised that then the hand positions wouldn't fit their gun again :/. ANY idea how to make that possible? Thank you so much for any reply!
     
  12. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    There is no solution that will satisfy an infinite number of possibilities perfectly. Every FPS I have played had a limited number of guns. Even the ones with player customization, the base gun was still the same and the hands didn't need to move no matter how many modifications were on the gun.
     
    theANMATOR2b likes this.
  13. Hinkel

    Hinkel

    Joined:
    Feb 19, 2017
    Posts:
    9
    Ok. Thank you very much for your reply!