Search Unity

Non-uniform scaling issue with mecanim

Discussion in 'Animation' started by Velo222, Feb 18, 2014.

  1. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    I have a "swordsmen/knight" character model in my game. Using mecanim, if the transform scale is uniform (for example Vector3(1,1,1)) Then everything behaves exactly as it should. If, however, I change the transform scale to something like Vector3(3, 1, 3), then my character's main body mesh works good, but his sword moves apart from his hand and so does his shield.

    So basically, if I use a non-uniform transform scale, the sword moves with the animation as if it's working okay, but it's far away from his hand.

    In Legacy, I can scale non-uniformly without any problems. Is there a way to non-uniform scale mecanim characters without having to re-rig the character again?
     
  2. Alf203

    Alf203

    Joined:
    Dec 7, 2012
    Posts:
    461
    I can scale non-uniformly with mecanim and it works for me but my weapons are separate objects which are not skinned and are children of certain bones.The bones drive the motion.

    Are the sword and shield skinned by any chance ?
    Are they part of your character's skinned mesh or separate (a second skinned mesh) ?
     
  3. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Hey Alf,

    The sword and shield are not skinned at all. They are just gameobjects with a mesh filter and mesh renderer (but no skinned mesh renderer). In my character models import settings, under "Rig" I am using mecanim, and I exposed two transforms of the model -- with "optimize game objects" checked. I exposed the right hand and left forearm (I'm not quite sure if those are actually bones, or just transforms.....or maybe they're the same thing?).

    So, to answer your second question, the sword and shield are actually separate game objects that are children of the exposed transforms I mentioned above.

    I thought that, since I have the sword and shield positioned where I want them before the game starts relative to the exposed transforms, that they would stay in the same place relative to them. However, when I press play to play my game, they get offset for some reason.

    I forgot to mention, also, that I used Mixamo's auto-rigger to rig this character, and perhaps the auto-rigger does is not designed to work with Unity's mecanim system? I'm just guessing though, I really don't know what the exact cause could be.
     
  4. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,437
    Ok, I did a little more testing and noticed something interesting. I created a simple cube and made it kind of to fit a sword-ish shape. The moment I make the cube a child of my gameobject character, the cube rotates (as if it's being modified by the bone structure of the character or something). Which, might be normal, I don't know (I think it takes on the parents rotation).

    But, the weird part is, looking at my cube's box collider, the more I rotate my cube while it's a child of the exposed transform, the collider rotates slower than the renderer for about 45 degrees, then at 90 degrees it comes back together again.......it all seems related somehow, but I can't figure out how. It doesn't matter if I make the cube a child of the main body mesh, or a child of the exposed hand transform, either one will cause this effect.

    Here are a couple pictures that might help. The first shows the cube when it's basically straight up and down (lets say that's 0 degrees -- although probably not actually). Then as I rotate it, the collider actually separates from the cube's renderer. I think that's kind of representative of what's actually going on -- but I don't know whats causing it.

    Picture 1:
    $Mecanim_rotation_parented1.png


    Picture 2:
    $Mecanim_rotation_parented2.png


    Picture 3:
    $Mecanim_rotation_parented3.png


    Shouldn't the collider stick with the renderer as I rotate it?
     
    Last edited: Feb 22, 2014
  5. Alf203

    Alf203

    Joined:
    Dec 7, 2012
    Posts:
    461
    Hi Velo222! Yeah its strange because that should be case. They should not be getting offset unless of course your sword and shield are not being scaled by the same amount as your character.


    You are right. Something is odd here… I've never encountered this before. Edit: Try to put a rigidbody on the cube, it might be because its trying to move a static collider and so delaying the operation ?

    As for Optimize Object I have never used that feature because I need to access the transforms when I'm doing IK. My guess would be that it could have something to do with that feature rather than how your character is skinned (auto rigger should work fine with Mecanim).

    Anyways, my first suggestion put the rigidbody and then my second would be to give it a try without the Optimize gameobject and see if that is the culprit. Otherwise, if you can make a .package with the character from your screen and the cube/stick, I wouldn't mind taking a look. I'm kind of curious now !
     
    Last edited: Feb 23, 2014