Rotate child without deforming it (without Gimbal lock)

Hello,
I am trying to rotate a transform so that it is always facing up (gobal). This transform is a child of another gameobject that has NOT a (1,1,1) scale: this results in the child deforming when rotating.

I know this is a normal phenomenon, but i couldnt find a way to counter its effects whitout also implementing a “Gimbal lock”, which is not ideal since i’m tryng go make a flying object that should freely move in the tridimensional space.

Is there some kind of solution to this other than changing the parenting hierarchy?

Thanks for reading

the only way I was able to fix this, since children scale off their parent, is make a separate parent for the “hinge” of the object that needs rotating.

So say you had a “body” parent with scale (1.5,2,1), and the arm was childed to that, if you rotate the arm it’s trying to base it’s scale off the body scale. So make a “spine”(empty gameObject) with scale (1,1,1), child the body to that. Then make a “shoulder”(empty gameObject) with scale (1,1,1) and make it a child of “spine” and child the arm to “shoulder”.

This way, each rotating position is properly scaled to (1,1,1)

It may actually suffice to „counterscale“ the child. If the parent is scaled 2,3,4 the child scale would have to be 1/2,1/3,1/4 to be back at a 1,1,1 world scale. Not sure if this affects rotation but I had to do that in the past for some reason I can‘t remember.

By and large, it’s good practice that any object that has children should just never be scaled. Put the mesh or whatever it is that needs scaling as a child, and leave the parent at 1,1,1.

This would break the instant you tried to rotate the child.

Thanks for the answers, i’ll change the hierarchy then and make sure the parent is 1,1,1

Yes, this even increases performance / reduces overhead as Unity can actually optimise hierarchies which are uniformly scaled or not scaled at all. Non uniform scaling can break many things such as batching. While it’s convenient to scale objects as you see fit, it’s better when things already have the proportions they should have.