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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

When rotating child objects, they deform when rotating

Discussion in 'Physics' started by DroidifyDevs, Sep 28, 2016.

  1. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    Hello!

    So I'm trying to do the easiest of things, rotate an object. Here's the code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class WheelRotator : MonoBehaviour {
    5.  
    6.     public int speed;
    7.     // Use this for initialization
    8.     void Start ()
    9.     {
    10.      
    11.     }
    12.  
    13.     // Update is called once per frame
    14.     void Update ()
    15.     {
    16.         transform.Rotate(Vector3.forward, speed * Time.deltaTime, Space.World);
    17.     }
    18. }
    19.  
    Seems easy. Problem is, I absolutely need the object to be a child of another object (due to how I'm generating the game's world). However, when rotating a child object, it gets stretched and distorted awfully:


    It's incredible that I've been in Unity for about a year and only now got stumped by this. It gets stretched even when changing the Z component in the editor manually. Is there any way at all to rotate a child gameObject without messing up its shape?

    Thank you!
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,998
    Check the parent scale, if its not uniform (like 1,1,1) i think that happens..
     
    Whatever560, ThisRyz and jmoocow2003 like this.
  3. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    Parent scale is 15, 1, 1. Do I need to make another parent that is 1, 1, 1? I'm very surprised by this lol
     
  4. samf1111

    samf1111

    Joined:
    Sep 18, 2019
    Posts:
    16
    the scale can also be (0.6, 0.6, 0.6) or (500, 500, 500), or anything as long as the x, y, and z values are the same!

    if thats what "uniform" means, then sorry for taking some of your credit, mgear.
     
    OronC likes this.
  5. djgriff

    djgriff

    Joined:
    May 29, 2014
    Posts:
    279
    Interesting i did this, created a new transform then child ed my collection of objects and nested objects and still distorted the children. 2019.3. not behaving very nicely :)
     
    albertjames likes this.