How does the child transform work?

So I have a gun and when I pick it up i’m making it a child of the a weapon holder. I’m trying to adjust the weapon rotation so that when its aiming its facing forward, but the values change when I make it a child and the rotation becomes completely different. I get that making it a child means the parent becomes like the origin point but how do i get the rotation values to stay the same when the gun becomes a child. I’m using eularAngles to set the rotation of the object.

Thanks!

When you have a transform that is child of another, you can change its position and rotation in two ways:

  • Relative to its parent: you can use localRotation, localEulerAngles and localPosition to change this values depending on the parent position and rotation. For example, if the parent position is (1,2,3) and you set the transform.localPosition to (2,2,2), the transform real position will be (3,4,5).
  • Relative to the world coordinates: you can use rotation, eulerAngles and position to change this values independently from the parent position and rotation. For example, if the parent position is (1,2,3) and you set the transform.position to (2,2,2), the transform real position will be (2,2,2).

I hope this helps you to understand how parenting works!

(this rules do not apply to real life parenting)