Search Unity

[SOLVED] Scale of Model changes during animation?

Discussion in 'Animation' started by Mattfro118, Sep 19, 2015.

  1. Mattfro118

    Mattfro118

    Joined:
    Jun 25, 2013
    Posts:
    7
    Hello everyone, I'm having an issue with the scale of my model being distorted on animation. I have an axe that appears fine when standing idle, however during the animation, about half way through it becomes very short and thick. Once the animation completes and it returns to the non-animated state, it is once again normal. If it makes any difference, there is a box collider attached to the head of the axe, and the whole gameobject is being instantiated as a prefab. To get a better idea of whats happening, please see the pictures I've attached. If you happen to know what is causing this, or have a suggestion for diagnosing the problem, please feel free to let me know :D


    ***EDIT***
    Also, the scale section of the object's transform component stays the same throughout the animation


    [The distorted version during an animation]
    ShortAxeAnim.png


    [The normal version standing idle]
    LongAxeAnim.png
     
  2. MadeThisName

    MadeThisName

    Joined:
    Mar 14, 2015
    Posts:
    115
    Its hard to tell whats happening without more information. Have you Scaled the transform of the axe since importing into your project?
     
  3. Mattfro118

    Mattfro118

    Joined:
    Jun 25, 2013
    Posts:
    7
    Yes, the model was originally imported too large and has been scaled down to .25 in each dimension. I apologize for not including more, if there is any other information that may help troubleshoot this, please feel free to let me know,
     
  4. MadeThisName

    MadeThisName

    Joined:
    Mar 14, 2015
    Posts:
    115
    try only scaling the parent transform of the axe with the animator and not the child if any.
     
  5. Mattfro118

    Mattfro118

    Joined:
    Jun 25, 2013
    Posts:
    7
    The axe itself is a single gameobject, which is instantiated under an empty gameobject i've named "itemholder". the itemholder gameobject has a scale of one, and I've tried adjusting the scale of it, but to no avail. I do not understand what's causing this problem. I'm going to grab a different weapon model and create a simple animation for it and see if i run into the same problem, or if its an issue local to that object and animation.
     
  6. Endless_Aftermath

    Endless_Aftermath

    Joined:
    Jan 11, 2014
    Posts:
    2
    Hey Matt. I've ran into this problem before, I believe. The problem is the instantiation. I don't know exactly what happens other than when you instantiate something to a moving object, every rotation and movement skews the instantiated object. Try this: instead of instantiating the weapon onto the character, have all of your weapons already attached to the character. When switching between weapons, just enable or disable the gameobject. I assume you were using GameObject.Destroy() and GameObject.Instantiate() to control all your weaponry needs. Although it seems like it would work...for some reason it complicates things. Give it a try and let me know if this helps.
     
  7. Mattfro118

    Mattfro118

    Joined:
    Jun 25, 2013
    Posts:
    7
    Thank you Endless_Aftermath, that solved the issue. I'm not sure what it is about instantiating the prefab as a child that screws up the model so bad during animations, but simply enabling/disabling it instead works like a charm. Hopefully this will save someone else the time and hassle of going through the same issue.
     
  8. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi there,

    I make a guess and I think there is nothing else going than non-uniform scaling of parent object which is poison to all 3d animation :).

    Your character looks like it's scaled unity cube, as it's cube, you made it taller like character, and scale might be something like 1,2,1. Now, when you add add let's say empty gameobject to scene, it has scale of 1,1,1, (hand).

    If you *manually* parent your hand object under your 1,2,1 scale character in editor hierarchy, Unity will automatically scale it inversely, so that it looks like nothing happened, even though it now lives in vertically distorted "parent space".
    If you check it, empty / hand object now has scaling of 1,0.5,1 instead of 1,1,1.

    Now this is most likely what you do without noticing it, when you include weapons with character.

    But when you cloned / instantiated the weapon to your characters hand using scripting, hand object most likely had scale of 1,1,1 - It doesn't have the "back transformed" scale space correction and this will result in your axe animations to be vertically squeezed / scaled as it's child of hand, and it's parent has scale of 1,2,1.

    EDIT:
    So I'd say it has nothing to do with scale of axe, neither with using or not using instantiate as suggested above as solution.
     
  9. Mattfro118

    Mattfro118

    Joined:
    Jun 25, 2013
    Posts:
    7
    Hey eses, I appreciate your feedback, and your are correct in that it is indeed a manually scaled unity cube as a character model place holder. Your theory would make sense, however being that the previous solution solved the issue and I already modified my code, I cannot confirm this with certainty. I will definitely make a note of this for future encounters. Although extremely useful, the transform component seems to be a bit fragile in that small changes in a parent can alter everything.
     
  10. markoal

    markoal

    Joined:
    Aug 31, 2015
    Posts:
    30
    I had trouble with something similar but different.
    I have an enemy that is scaled differently on different animation. Although it should be for example scale on 1, on different animation it automatically scales on eg. 0.5.
    If someone else is facing that issue, just recreate AnimatorController for that model, do not copy paste other animator controller.