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. Voting for the Unity Awards are OPEN! We’re looking to celebrate creators across games, industry, film, and many more categories. Cast your vote now for all categories
    Dismiss Notice
  3. Dismiss Notice

Animating humanoid model with muscles

Discussion in 'Animation' started by AntiProfessional, Mar 5, 2018.

  1. AntiProfessional

    AntiProfessional

    Joined:
    Feb 28, 2018
    Posts:
    4
    Hey community,
    I already asked this question in 'Scripting', but I think it was the wrong forum i guess. Also I think it was a bit unclear what I am trying to achieve.
    I am currently trying my luck with Unity and I kinda like it.
    I've created an humanoid model with a rig and an animation attached with blender.
    I've imported my model to a Unity scene and it works to move and look around (Controlled by the Standard FirstPersonController). Also my Animation (which just raises the hands) works without problems.
    Now i want to move fingers when the user presses some keys on the Keyboard (e.q. close the index finger when pressing 'F' on the keyboard). I tried that by using the HumanPoseHandler with a humanPose, but it's not working.
    Code (CSharp):
    1.         private Animator m_Animator;
    2.         private bool m_ShowHands = false;
    3.         private bool m_UnshowHands = false;
    4.  
    5.         private bool m_MoveFingers = false;
    6.  
    7.         private HumanPose humanPose;
    8.         private HumanPoseHandler humanPoseHandler;
    Code (CSharp):
    1.         // Use this for initialization
    2.         private void Start()
    3.         {
    4.             m_Animator = GetComponentInChildren<Animator>();
    5.             humanPose = new HumanPose();
    6.             humanPoseHandler = new HumanPoseHandler(m_Animator.avatar, transform);
    7.             humanPoseHandler.GetHumanPose(ref humanPose);
    8. // some other stuff follows here from the FirstPersonController
    9. }
    In FixedUpdate I get the userinput, which works fine.
    Now, I heard that my animations might get overwritten from my animationcontroller, thats why I've put my script in 'LateUpdate', which should move my index finger
    Code (CSharp):
    1.         private void LateUpdate()
    2.         {
    3.             if (m_MoveFingers)
    4.             {
    5.                Debug.Log("manipulate indexfinger-right");
    6.                 humanPoseHandler.GetHumanPose(ref humanPose);
    7.  
    8.              
    9.                 humanPose.muscles[79] = -40f;
    10.                 humanPose.muscles[80] = -40f;
    11.                 humanPose.muscles[81] = -40f;
    12.                 humanPose.muscles[82] = -40f;
    13.  
    14.                 humanPoseHandler.SetHumanPose(ref humanPose);
    15.             }
    16.         }
    But when I set m_MoveFingers to true, nothing happens. The Debug.Log is called, but the model won't move. I removed the Controller from the Animator, but it still doesn't move. When I set m_MoveFingers to true again, the values are reset and not -40f.
    My AnimatorController attached to the model is the one which comes with the ThirdPersonController Standard Asset.

    I am kinda lost right now and not sure how I can fix this. I haven't created an animation which moves the finger, I simply want to move the fingers with the muscles. I am not sure if thats possible. So my goal is to manipulate the bones of my model by manipulating the muscles.

    I appreciate every help. Thank you in advance.
     
    CloudyVR and david-mal like this.
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Consider setting the rig to generic rather than humanoid. I think this will solve the issues you are encountering.
     
    AntiProfessional likes this.
  3. AntiProfessional

    AntiProfessional

    Joined:
    Feb 28, 2018
    Posts:
    4
    Thanks for your answer. I need the rig to be human to use the avatar. So I think it's no option to set the rig to generic.
    I just found out that if I am not using a Runtime Animator Controller, it works to manipulate the rig by muscles. Setting the Controller to null before manipulating the muscles also works. So I think the controller is overwriting the pose. Can't i freeze the animation which puts the hands in front of the face and then move the fingers?
    Is there a better way to manipulate the model? I need it to be precise, because it should basically represent the finger movements of a real person.

    //Edit
    I found a way to "freeze" the animation. I get the current humanPose from the humanPoseHandler and save it in an object. Now i remove the animatorcontroller and set humanPose again. When I manipulate the muscles now, it works! :)

    humanPoseHandler = new HumanPoseHandler(m_Animator.avatar, transform);
    humanPoseHandler.GetHumanPose(ref humanPose);
    m_Animator.runtimeAnimatorController = null;
    humanPoseHandler.SetHumanPose(ref humanPose);


    But now the model falls through the floor plane and I don't know why.
     
    Last edited: Mar 5, 2018
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Humanoid rig is (mostly) for externally created animations, from my experience. You might find a solution with the built in IK solution for mecanim, but I don't know if it will work on fingers.
    What purpose do you need for the avatar? The avatar is mostly needed for retargeting and masking of joints from animations?

    Sorry - I'm a animator not a programmer - so the info provided in the first post is kind of mystical.
    If you are creating the animations via code - what purpose does humanoid rig and avatar serve?