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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Update Humanoid muscle

Discussion in 'Scripting' started by The-Little-Guy, Dec 19, 2015.

  1. The-Little-Guy

    The-Little-Guy

    Joined:
    Aug 1, 2012
    Posts:
    297
    I have the following code within a class that extends EditorWindow I have sliders within that window, and when the sliders move it will change the muscle (open/close). For some reason, the muscle is not updating. I have tried many different numbers for the muscle value but the pose for the character is not changing. Do I need to do something else to update the avatar's pose?

    Code (csharp):
    1.  
    2.     Avatar avatar;
    3.     Animator anim;
    4.     HumanPoseHandler humanPoseHandler;
    5.     HumanPose humanPose;
    6.  
    7.     // When the item is selected setup the information
    8.     void OnSelectionChange() {
    9.         avatar = anim.avatar;
    10.         BoneInfo hips = GetBoneInfo(HumanBodyBones.Hips);
    11.         humanPoseHandler = new HumanPoseHandler(avatar, hips.transform);
    12.         humanPose = new HumanPose();
    13.         humanPoseHandler.GetHumanPose(ref humanPose);
    14.     }
    15.  
    16.     // When the GUI slider moves do this:
    17.     void OnGUI() {
    18.         BoneInfo index1 = GetBoneInfo(HumanBodyBones.LeftIndexProximal);
    19.  
    20.         humanPose.muscles[(int)index1.muscleId.y] = -100;
    21.         humanPose.muscles[(int)index1.muscleId.z] = -100;
    22.  
    23.         humanPoseHandler.SetHumanPose(ref humanPose);
    24.     }
    25.  
    26.     BoneInfo GetBoneInfo(HumanBodyBones id) {
    27.  
    28.         int boneid = (int)id.GetHashCode();
    29.         BoneInfo info = new BoneInfo();
    30.  
    31.         info.boneId = boneid;
    32.         info.muscleId.x = HumanTrait.MuscleFromBone(boneid, 0);
    33.         info.muscleId.y = HumanTrait.MuscleFromBone(boneid, 1);
    34.         info.muscleId.z = HumanTrait.MuscleFromBone(boneid, 2);
    35.  
    36.         info.muscleMax = HumanTrait.GetMuscleDefaultMax(boneid);
    37.         info.muscleMin = HumanTrait.GetMuscleDefaultMin(boneid);
    38.         info.transform = anim.GetBoneTransform(id);
    39.  
    40.         return info;
    41.     }
    42.  
     
    kite3h and soltex1 like this.
  2. soltex1

    soltex1

    Joined:
    Apr 2, 2015
    Posts:
    14
  3. The-Little-Guy

    The-Little-Guy

    Joined:
    Aug 1, 2012
    Posts:
    297
    I don't know why you are getting that, it looks right to me...
     
  4. soltex1

    soltex1

    Joined:
    Apr 2, 2015
    Posts:
    14
    Thanks for the answer. I've tried at least with 4 versions and still the same. I really needed those libraries, not only to run your code, but to do something with the muscle values.
    (A better version of this would be great to do: https://www.assetstore.unity3d.com/en/#!/content/32233)

    Did you try post your question in another forum? Stackoverflow maybe?
     
    Last edited: May 9, 2016
  5. itsjustmeagain

    itsjustmeagain

    Joined:
    Dec 1, 2016
    Posts:
    14
    Do you have any ideas if this is the secret to be able to create humanoid animations by scripting in Unity ? Maybe we can collect all information about this at some place?
     
  6. NumesSanguis

    NumesSanguis

    Joined:
    Nov 9, 2017
    Posts:
    6
    Last edited: Feb 13, 2018