I am making my own game editor, but have encountered the following problem:

I have two objects, A and B.

A's initial values:

Position: (3,3,3), Rotation: (45,10,0), Scale(1,2,2.5) 

B's initial values:

Position: (1,1,1), Rotation: (10,34,18), Scale(1.5,2,1)

If I now make B a child of A, I need to re-calculate the B's Position, Rotation and Scale relative to A such that it maintains its current position, rotation and scale in world coordinates. So B's position would now be (-2, -2, -2) since now A is its center and (-2, -2, -2) will keep B in the same position.

I think I got the Position and scale figured out, but not rotation.

So I opened Unity and ran the same example and I noticed that when making a child object, the child object did not move at all. but had its Position, Rotation and Scale values changed relative to the parent.

For example:

Unity (Parent Object "A"):

Position: (0,0,0)
Rotation: (45,10,0)
Scale: (1,1,1)

Unity (Child Object "B"):

Position: (0,0,0)
Rotation: (0,0,0)
Scale: (1,1,1)

When B becomes a child of A, it's rotation values become:

X: -44.13605
Y: -14.00195
Z: 9.851074  

If I plug the same rotation values into the B object in my editor, the object does not move at all.

How did Unity arrive at those rotation values for the child? What are the calculations?

If you can put all the equations for the Position, Rotation or Scale then I can double check I am doing it correctly but the Rotation is what I really need.


1 Answer 1


Put some research in using Matrices.

Use a Matrix for each child object and matrix for the parent object. First transform all the objects with the child matrix, then transform all the objects with the parent matrix. This way when you transform the parent matrix all childs will transform with it.

You could take a look at my question: Transform coordinates from 3d to 2d without matrix or built in methods

  • \$\begingroup\$ Definitely matrices are the way to go. The basic transforms are Translation, Rotation and Scale - more or less like the parameters you ask about except that you ask about absolute whereas the matrices contain relative transformations. You can 'combine' matrix transforms by multiplying them, just remember to keep the order OK. \$\endgroup\$
    – Liosan
    Commented Oct 23, 2012 at 7:48
  • \$\begingroup\$ Hello Everyone. Yeah my object have their own World matrix where I have the combination of Scale, Rotate, Translate. But why does the child Rotation values contain(in Unity) X: -44.13605 Y: -14.00195 Z: 9.851074 when the parent rotation values are (45,10,0). My logic tells me that the child should produce something like (-45,-10,0) to cancel the parent's rotation and keep the object on the same position. \$\endgroup\$ Commented Oct 23, 2012 at 13:52
  • 1
    \$\begingroup\$ The child should not cancel the parents rotation, the parent rotation is transforming the child also. This is why you get values you don't expect. If the parent rotates, the child rotates also but with slightly different values since it's position is not exactly the same. Take a piece of paper (rectangular) and draw a square on one corner. Now rotate the paper by 45 degrees, you'll notice the square is not rotated by the same 45 degrees \$\endgroup\$
    – Thomas
    Commented Oct 24, 2012 at 9:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .