How to set rotation of child independent of parent

I have a gameobject inside a gameobject:

  • Object1
  • Object2

Object 1 has a script that constrains its X axis to 20 degrees.

Object 2 has a script that constrains all of its axis’ to 0 degrees.

The result is that Object1’s rotation is 20,0,0 and Object2’s rotation is 340,0,0:

  • Object1 - 20,0,0
  • Object2 - 340,0,0

How can I get Object1’s X axis rotation to stay at 20, while maintaining Object2’s rotation of 0,0,0?

Bonus question: Is it then possible to change Object2’s Y axis to whatever I want?

Thank you :slight_smile:

If you are trying to make the rotation of Object2 to identity (0, 0, 0) in terms of the world space use transform.rotation, i.e.

Object2.transform.rotation=Quaternion.identity;

If you are trying to make the rotation of Object 2 to identity in terms of the local space (so (0, 0, 0) in the inspector) use transform.localRotation, i.e.

Object2.transform.localRotation=Quaternion.identity;

the script should go at the parent (Object1) , then this one fix its rotation whatever and fix a specific or all child localRotation. Because is it the knife who decide or the knight ?