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

Sprite changes form when rotating

Discussion in '2D' started by Fluffy_attack_, Oct 25, 2022.

  1. Fluffy_attack_

    Fluffy_attack_

    Joined:
    Oct 16, 2022
    Posts:
    5
    Hi everyone

    My sprite deforms when I rotate it.

    Update I removed the Sprite from its parent and now its fine but can someone help me understand why this happens?


    Screenshot 2022-10-25 135206.png


    Screenshot 2022-10-25 135818.png
     
    Last edited: Oct 25, 2022
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,353
    Not sure either but it happens in 3D as well. I end up always having to make edits while it is unparented, and then reparent it. Probably has something to do with trying to stay aligned and scaled properly with its parent.
     
  3. karliss_coldwild

    karliss_coldwild

    Joined:
    Oct 1, 2020
    Posts:
    530
    To be more precise this happens when parent objects have non uniform scale (different scale values for each axis).

    All the transformations of parent objects get applied to child objects it's the whole point of transform hierarchy. All transformations mean position rotation and scale. For most cases it's reasonable. You move the parent -> children move. You rotate the parent -> parent rotates together with parent. You make the parent twice as big children get also twice as big. But if you stretch the parent only in single direction (and child is rotated) it means that child will now be stretched in direction which doesn't match the direction of child object which results in skewed look similar to what can be seen in screenshot above. You would see the same result if you tried to apply sequence of rotations and stretching in photoshop (or 2d drawing software of your choice).

    Here is an example representing stretching of child object (not strictly required), rotation of child object, stretching of parent object.

    upload_2022-10-25_18-28-30.png


    Solution is simple don't use non uniform scaling! Skewed visuals isn't the only problem it will cause.

    If you really need to use non uniform scaling apply it only to final elements in the object hierarchy, don't apply it to intermediate objects. If necessary move the visuals from parent to an additioanal child object so that you don't have to scale the parent.

    Instead of this
    Code (csharp):
    1. * GameObject0 (visual 1) (you want to stretch visual 1)
    2.    * GameObject1 -> some other object in hearachy
    3.       * GameObject2 (visual 2)
    Do this

    Code (csharp):
    1. * GameObject0
    2.     * GameObject0_visual (visual 1) -> stretch this instead of GameObject0 thus avoid stretching whole tree
    3.     * GameObject1
    4.         * GameObject 2 (visual 2)
     
    Last edited: Oct 25, 2022
  4. Fluffy_attack_

    Fluffy_attack_

    Joined:
    Oct 16, 2022
    Posts:
    5
    Ooooo okay that makes sense

    Thank you so much I appreciate the help:D