- Home /
Parent-independent rotation
Is there a simple way to make an object independent of its parent's rotation so that its rotation can be controlled without the parent's rotation affecting it? Here is the code I am using to rotate the child:
myChild.transform.Rotate(0,0,1);
The idea of parenting is to make the child depend on the parents transform, so your only way to achieve this would be to rotate the child inverse to the parent.
Answer by Tetrad · Jun 20, 2010 at 07:54 PM
You could always store your own Quaternion, do all your rotation on that, and at the end of every frame (i.e. in LateUpdate
), set the transform.rotation (which means world rotation) to your Quaternion.
Alternatively, you could write a script that does a "fake" parenting for location. So every frame hammer your object's world position (transform.position) to the parent transform's world position.
Answer by _Petroz · Jun 15, 2010 at 09:18 AM
You can use transform.LookAt on the child and it wont be affected by the parent's rotation.
You can also use transform.Rotate( Vector3 axis, float angle ) to rotate around a specified axis, allowing you to compensate for the parent rotation.
LookAt did the trick for me, I needed my child object to always take the parent translation but I wanted the rotation to always be fixed.
Thanks for the suggestion!