Hi,

So, imagine a cube. This is the larger parent. This cube is made up of a bunch of smaller cubes in a 3x3x3 formation. Each of these smaller cubes is a smaller parent made up of six faces. Large Cube > smaller cubes > faces.

I need the positions of the faces. transform.position gives me their world position, transform.localPosition gives me their position local to the smaller cubes. I want to get their local position in terms of the larger cube space.

If I have to I can take the local positions of the faces in terms of the smaller cubes and convert them with some math, but is there a simpler way?

Thanks!

That’s quite simple. The process is always the same:

// given
Transform parentObj;
Transform nestedChild;
Vector3 localPointInNestedChild;

Vector3 worldPoint = nestedChild.TransformPoint( localPointInNestedChild );
Vector3 localPointInParent = parentObj.InverseTransformPoint( worldPoint );

If you just want the position of an object in local space of another object you can directly use:

parentObj.InverseTransformPoint( child.position );

edit

If you need to transform a lot points from one space to another you can simply create a conversion matrix by combining the right worldToLocal and localToWorld matrices.

Keep in mind that matrix multiplications work in reverse order. So if you have a source space and a destination space you would do:

Matrix4x4 m = dest.worldToLocal * source.localToWorld;

Now you just have to multiply each point with that matrix:

Vector3 pointInDest = m * pointInSource;