Search Unity

  1. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  2. We are looking for feedback on the naming of a new user research platform that we are working on.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Scaling bones

Discussion in 'Scripting' started by NeilM0, Mar 25, 2010.

  1. NeilM0

    NeilM0

    Joined:
    Mar 31, 2009
    Posts:
    135
    Does anyone know how to locally scale a bone in unity? transform.localScale isn't a local scale.

    I take an object with a bone hierarchy and I scale the root bone down. I then want a child to still be at 1:1 scale. So I'm finding that particular transform and trying to scale it back up without skewing. It sways from side to side so I figure I have to scale up in the local transformation. Unfortunately I can't figure out the correct combination of commands. I've tried messing with TransformDirection, and the localToWorldMatrix/worldToLocalMatrix commands with no luck. Can anyone help me out?

    Code (csharp):
    1.  
    2.     void LateUpdate()
    3.     {
    4.  
    5.         GameObject skeleton = GameObject.Find("character");
    6.         Component[] transforms = skeleton.GetComponentsInChildren(typeof(Transform));
    7.  
    8.         skeleton.transform.localScale = new Vector3(1f, 0.61583f, 1.0f);
    9.  
    10.         foreach (Transform t in transforms)
    11.         {
    12.             if (t.name == "head")
    13.             {
    14.                 Vector3 scaleVector = Vector3.one;
    15.                 scaleVector.x /= skeleton.transform.localScale.x;
    16.                 scaleVector.z /= skeleton.transform.localScale.y;
    17.                 scaleVector.y /= skeleton.transform.localScale.z;
    18.  
    19.                 t.localScale = scaleVector; // skeleton.transform.TransformDirection(scaleVector);
    20.  
    21.             }
    22.     }
     
  2. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    653
    I have the exact same problem, did you have any luck finding a solution to this ?

    It seems like something that really should be possible.
     
  3. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    653
    Ok I have a work around for this, if anyone else is interested.

    Lets say I want to scale up a characters upper arms to make them look more muscular, but I don't want to mess up the scaling of the lower arms/hands.

    What I do is add an extra bone that is a child of the upper arm and runs parallel to the upper arm. This new bone has no children. I use the new bone for scaling the arm, and the original bone for rotating it. The new bone has all the weighting (the old bone has no vertex weights at all, it doesn't need them because it has the new bone as a child).

    Now I can scale the upper arm as I want with the lower arm staying the same.

    Hope this helps someone.
     
    Just2Ask likes this.
  4. Esila

    Esila

    Joined:
    Mar 22, 2009
    Posts:
    105
    Zomby138, I am using CS bone in 3dsmax, how to add an extra bone???
     
  5. Just2Ask

    Just2Ask

    Joined:
    Feb 24, 2018
    Posts:
    10
    Sorry for the incredible 'necro', but thank you for this!
    this sounds like its what I am after, but I don't quite understand..

    I duplicated the thigh bone named ThighLeft (for example) and made the thigh bone (ThighLeft) the parent of the duplicate (ThighLeftDuplicate), but nothing happens when I scale rotate or move ThighLeftDuplicate.

    It has no weight painting like you said, but it also does literally nothing..
    Any help would be most appreciated
    I am doing this in Blender
     
  6. ikazrima

    ikazrima

    Joined:
    Feb 11, 2014
    Posts:
    308
    @Just2Ask
    Duplicating the bones will not assign the proper weights to the new bone, since each vertex group is assigned according to the bone group / name.
    You need to copy the weights from the original bone to the helper bone. Or renaming the vertex group to the new bone.
     
    Just2Ask likes this.
  7. Just2Ask

    Just2Ask

    Joined:
    Feb 24, 2018
    Posts:
    10
    Thank you for the response; I really appreciate it
    I will try this out
    -
    It worked 100%!!
    I cant thank you both enough!
     
    Last edited: Oct 6, 2018
    ikazrima likes this.
  8. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    653
    Wow, what a blast from the past! I'm glad my post was able to help someone so long after it was written.

    I should mention that if I wanted this sort of behavior today I would probably use shape keys rather than bone scaling.
     
    Just2Ask likes this.
unityunity