- Home /
Rotating an object within its parent's scale
I have made a cube in a 3D modelling application. It consists of 6 separate planes as sides, and then aligned so that it looks like a regular cube.
I bring it into Unity, and I scale the cube. (Let's say it's Vector3(2.0, 1.5, 3.0), but any scale should work.) I then rotate one of the sides in the Unity editor by 90 degrees. This skews the side as I rotate, but at 90 degrees, the shape looks exactly the same – just the texture has appeared to rotate 90 degrees. This is what I want, so far so good.
I want the same type of thing to happen in scripting, so I rotate the side with this code:
sides[sideID].mesh.transform.Rotate(0, 0, 90);
//sides[sideID] is one of the sides of the cube that I have chosen
When I add this code into the Start() function, the cube side rotates exactly as I'd hoped. However, if I add this code into a later function while the game is running, the side simply rotates, stretched in the wrong direction, as though the scale of the parent has been baked into the child.
Is there anything I can do about this? Why does this work in Start() and not later?