- Home /
rotation of child object inside another simultaneously rotated object
Hi - I'm getting some weird things happening when I rotate a child object inside its parent. Currently, the elements rotate with these functions:
parent.transform.rotation = Quaternion.AngleAxis(parentRotationAmount, Vector3.up); //rotating around the Y axis child.transform.rotation = Quaternion.AngleAxis(childRotationAmount, Vector3.right); //rotating around the X axis
which works if neither of them are rotating simultaneously, but if, as is the case in my game, the child object needs to rotate at the same time as the parent, what I get is that the child doesn't maintain its proper orientation to its parent (should be rotating only on the x axis, not y). Anybody know how I can fix this?
Answer by whydoidoit · Jun 14, 2012 at 09:34 PM
You need to use child.transform.localRotation and then it will move inside the parent's rotation. At the moment you are setting the global rotation and that is an absolute not a relative one.
Your answer
![](https://koobas.hobune.stream/wayback/20220613072803im_/https://answers.unity.com/themes/thub/images/avi.jpg)