- Home /
Scaling width/height of a character's head/body
I want to scale width/height of my character's head/body mutually independently.
But due to the bone structure as shown below, When scale the body(Hips bone), the head is also scaled.
Hips
Pelvis
...
Spine
...
Head
So my code is like this and it seemed to be worked.
void LateUpdate()
{
HipsTransform.localScale = new Vector3(hipsWScale, hipsHScale, hipsWScale);
HeadTransform.localScale = new Vector3(headWScale / hipsWScale, headHScale / hipsHScale, headWScale / hipsWScale);
}
But rotating the spine(for animation), the head is skewed. This is my problem.
I found that this is common mathematical issue but I want to know how to solve it.
Unity's transform matrix and global scale is read only. How should I do?
Is there any way to scale width/height of my character's head/body mutually independently?
Thanks.
Answer by sneftel · Jul 11, 2011 at 01:56 PM
Non-uniform scaling CAN be done for skeletons without causing skew. In order for it to work, though, you'll need to invert the scale in the next node down. There must be one of these auxiliary nodes for each child of the original bone which you want to scale, and it must have the translation from the original node, the inverted scale, and NO rotation. Suppose you had a character with the following bone structure:
Hips
Spine
LUpperArm
LForeArm
LHand
RUpperArm
RForeArm
RHand
Neck
Head
LThigh
...
In order for this to work, you'll need auxiliary nodes for LUpperArm, RUpperArm, and Neck:
Hips
Spine // Contains non-uniform scale
LUpperArmAux // Contains inverse scale of Spine, translation from LUpperArm, and no rotation
LUpperArm // Contains no translation
LForeArm
LHand
RUpperArmAux // Contains inverse scale of Spine, translation from RUpperArm, and no rotation
RUpperArm // Contains no translation
RForeArm
RHand
NeckAux // Contains inverse scale of Spine, translation from Neck, and no rotation
Neck // Contains no translation
Head
LThigh
...
All this, of course, needs to be supported by your animations (by expecting LUpperArm to be a child of LUpperArmAux, for instance). In your animation program, make sure the LUpperArmAux bone has zero length, the LUpperArm node is constrained to have no translation, and the LUpperArmAux bone has its joint limits set to identity. And when you skin your character, make sure to exclude the Aux nodes from affecting vertices.
Finally I adopt your way and now I can use non-uniform scaling, thanks Ben 12! (Because I don't need to translate bones, I simplified your method.) $$anonymous$$oreover, as Warwick Alison said, the performance is still good though I add bones which don't affect any skin vertex. It's all right! Thanks everyone!
Answer by Waz · Jul 04, 2011 at 11:55 AM
The skewing you see is exactly what you should expect. While you may seem to be scaling bones in Maya, perhaps you're just scaling the bone envelope. Regardless, once you have the model in Unity, any non-uniform scale of transforms will cause a skew in child transformed bones. You can see this effect in normal unskinned meshes too.
The reason is that scaling does not happen by a multiplying of X, Y, and Z independently, any more than position is merely the sum of parent transforms by independent axes. You would not want the arms to move 5 units along their Y local axis every time the player jumped the spine by 5 units vertically. So similarly, scaling the body by 5 times in the Y will not make the arms 5 times longer in their Y.
Only uniform (equal x,y,z) scaling will appear unskewed on child transforms (bones or otherwise). There is also no simple "unscaling" you can do in child bones.
As a corollary, you can safely scale the final bones non-uniformly (since they have no children).
Thanks Warwick.
I can't adopt the way in your another comment due to bone number limitation of my project.
But I'm going to try another method, hinted by your answer "can safely scale the final bones non-uniformly".
It doesn't still work... but thanks anyway!
To clarify by example, you can have a "tummy" bone attached to you "spine" bone, and scale the tummy to make the character fat, without affecting other bones (since none are connected to the tummy bone).
Also note that performance is more affected by the number of bones which actually affect any skin vertex than by the total number of bones.
All right, now I can scale spine by scaling tummy bone and without affecting other bones. And naturally fatted tummy mesh eat away at arms meshes... Yes "independently scale" is here, I am foolish.
Answer by Waz · Jul 04, 2011 at 10:42 PM
One way to do "scaling" is just to have two bones above move them further apart, thus stretching the skin between them. Combined with uniform scaling, this may be sufficient for what you're trying to do.
Answer by macs_yums · Jul 04, 2011 at 07:32 AM
And I am worried just about the same process.
Version 3.3 of my environment Unity3D, is the iPhone Pro Android Pro.
The local scale of the bone, what's a setting not solve, such as to affect the local scale of the bones of the child?
As far as experimenting with Maya, there is no problem changing the scale of the bones are free to In the same way I do it Unity3D.
Scaling of bone in the other games I use the Avatar seems like doing.
How well do you resolve it not?
This is a comment to the Question, not an Answer. If you could move it, that would help the indexing. TIA
Answer by Paulius-Liekis · Jul 11, 2011 at 12:52 PM
Yeah, don't do non-uniform scaling - it will look weird when you will start animating the character (for example hands will be longer when they are in front compared to when they are at the sides).