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

Put a weapon in mixamo animations

Discussion in 'Animation' started by edufissure, Jan 1, 2019.

  1. edufissure

    edufissure

    Joined:
    Oct 25, 2018
    Posts:
    66
    Hello, i have made one character using makehuman + generated fbx + generate different animations with mixamo ( dying, walking with gun, shooting.. etc...)

    upload_2019-1-1_13-29-56.png

    Then i would like to add a weapon ( gun taken form turbosquid). I have the gun imported in unity at seems ok...

    But if i put the character in scene as you can watch in above image, i can "see" left hand, left arm all the rig ( i have imported as humanoid rig and animations work very well).

    But in the fbx imported that you can see in the project hierachy, i cant modify the fbx, cant add a component or at least i dont know how...Ther

    Ideally would be to change one avatar adding the pistol ex: left hand, and that all were modified, in different animations including in all the pistol in left hand....There are only two "fixed parts" the mesh and the hips

    upload_2019-1-1_13-40-19.png

    I attach an image of one animation just to clarify ( i d like to include the weapon between the hands)

    upload_2019-1-1_13-35-53.png

    So i have other animations, pistol walk, pistol run, shooting, draft shooting...

    Summarizing a workflow or help on how to add an element in this case gun, to this animations.....

    Sorry for my bad english...

    Thanks

    Happy new year...
     
  2. edufissure

    edufissure

    Joined:
    Oct 25, 2018
    Posts:
    66
    Just in case somebody has the same problem ive been solved the issue with this solution, perhaps not the best but i think is quite polite:

    1 - Create an empty gameobject and attach it to the part of the body you want ( ex: left hand in my case).

    upload_2019-1-4_21-22-58.png
    Be sure that the object, ionGun position is 0,0,0.

    2 - Then in scene paused you can be more exact and changing the values of the gun holder

    upload_2019-1-4_21-24-39.png

    Notice that here is very important, as the gun depending on the 3d software you use can be rotated or the position can be different. Personally i prefer to change this settings in gunhulder ( empty gameobject).

    3 - Attach a script component to the player o character:

    upload_2019-1-4_21-27-3.png

    In the script itself pass the exact part of the body you want attach the gun. Then put the gun you want ( in this case put the gun no the holder, this worked for me).

    4 - The code of the script:
    Code (CSharp):
    1. using System.Collections;
    2.  
    3. using System.Collections.Generic;
    4.  
    5. using UnityEngine;
    6.  
    7.  
    8.  
    9. public class ikhandlerElyEnemyIonGun : MonoBehaviour {
    10.  
    11.  
    12.  
    13.  
    14.  
    15.     Animator anim;
    16.  
    17.  
    18.  
    19.     public float lhweight = 1;
    20.  
    21.     public Transform lhtarget;
    22.  
    23.  
    24.  
    25.     //public float rhweight = 1;
    26.  
    27.     //public Transform rhtarget;
    28.  
    29.  
    30.  
    31.     public Transform weapon;
    32.  
    33.     public Vector3 lookpos;
    34.  
    35.  
    36.  
    37.     void Start ()
    38.  
    39.     {
    40.  
    41.         anim = GetComponent<Animator> ();
    42.         weapon.transform.Rotate(-95,250,-90);
    43.     //    Vector3 temp = new Vector3(0.088f,0.219f,-0.183f);
    44.         //temp= weapon.transform.position;
    45.     //    temp.x=temp.x +1.0f;
    46.  
    47.         //weapon.transform.position = temp;
    48.     }
    49.  
    50.  
    51.     // Update is called once per frame
    52.  
    53.     void Update ()
    54.  
    55.     {
    56.  
    57.    
    58.  
    59.     }
    60.  
    61.  
    62.  
    63.     void OnAnimatorIk()
    64.  
    65.     {
    66.  
    67.         anim.SetIKPositionWeight (AvatarIKGoal.LeftHand, lhweight);
    68.  
    69.         anim.SetIKPosition (AvatarIKGoal.LeftHand, lhtarget.position);
    70.  
    71.         anim.SetIKRotationWeight (AvatarIKGoal.LeftHand, lhweight);
    72.  
    73.         anim.SetIKRotation(AvatarIKGoal.LeftHand, lhtarget.rotation);
    74.  
    75.  
    76.  
    77.         //anim.SetIKPositionWeight (AvatarIKGoal.RightHand, rhweight);
    78.  
    79.         //anim.SetIKPosition (AvatarIKGoal.RightHand, rhtarget.position);
    80.  
    81.         //anim.SetIKRotationWeight (AvatarIKGoal.RightHand, rhweight);
    82.  
    83.         //anim.SetIKRotation(AvatarIKGoal.RightHand, rhtarget.rotation);
    84.  
    85.  
    86.  
    87.  
    88.  
    89.     }
    90.  
    91. }
    In the start code there are some initializations that you have to adjust.

    I suppose it would be a better way to do this, not fine tunning here again the weapon position and rotation....After little tests, it works great...And i have attached different weapons to different characters with this steps and all worked fine...

    Thanks

    ps: Weight and position i left as default values, weight to 1 and lookpos to 0,0,0,..

    If anyone can improve this ....
     
    aigamestrees likes this.