- Home /
force child rotation to zero?
I've been trying to tackle this for far too long.. How do you force a child object to STAY at zero x rotation?
for some reason none of these work, and they are in an Update function too!
transform.rotation.x = 0;
transform.rotation.x = transform.root.rotation.x;
transform.localRotation = Quaternion.identity;
I only tried the last one to set it to the TOP parent's rotation. Didn't work! The rotation at best only keeps to the first parent's rotation. This prefab is a child of a child of a so and so forth.
what's up here? what am I missing? Thanks
Answer by Wolfram · Jun 11, 2011 at 01:55 PM
First of all, transform.rotation refers to World space, while transform.localRotation refers to local space. The values you see in the Inspector are always local space, but just because they are zero doesn't mean the object has no rotation, because one of the parents might.
Secondly, localRotation, as the name suggests, only refers to the LOCAL rotation, that is, the rotation relative to its DIRECT PARENT. This is the reason your last method did what you explained it did, and not what you intended to do.
Most importantly, however, any variant of "rotation" always refers to the Quaternion. You cannot set/access individual angles with these, without calling additional conversion methods. Instead, when dealing with angles, use tranform.eulerAngles and transform.localEulerAngles.
You should be able to figure out the correct settings from the explanations above.
Answer by Anxo · Jun 11, 2011 at 01:47 PM
you mean relative to world space?
so if you have Box A as a child of Box B, and you rotate Box B,you want Box A to stay still on the X axis?
I would have guessed that transform.rotation.x would have worked as long as it is in an update function but if not you might be able to chat it.
What if you have a empty game object outside with the desired X rotation and you tell Box A, transform.rotation.x = EmptyGameObject.transform.rotation.x;
That seams very unnecessary, I think we are just missing some Space.World parameter but when I get a chance to test it I will check it out.
Your answer
Follow this Question
Related Questions
Make a simple tree 1 Answer
How to fix Child Object Rotations.? 1 Answer
Child versus Parent rotations 3 Answers
Pointing a child at an object using its parents rotation 1 Answer
Why is a child object not rotating properly with parent? 1 Answer