Transform.TransformPoint(Vector3 point, Transform targetTransform)

Hi,

If I currently want to transform between coordinate systems I need to go through world space.

Something like:
Transform TransformPoint(Vector3 point, Transform origin, Transform target) {
return target.InverseTransformPoint(origin.TransformPoint(point));
}

Is there any way to do this in a more direct way without going through world space, e.g. I just want to convert to parent or parent of parent and in the case of big difference in scale, there can be float rounding errors?

Coordinates in Unity are based on the LocalToWorld/WorldToLocal-matrix that’s stored in the Transform.
So no, there is no ‘direct’ way.
A way to ‘remove’ one matrix from another is to multiply its inverse with your original matrix:
local_matrix = transform.parent.localToWorldMatrix.inverse * transform.localToWorldMatrix;

Coordinates in Unity are based on the LocalToWorld/WorldToLocal-matrix that’s stored in the Transform.

any code or doc pointers for that? What is this information based on?

You can read about the Transform component’s members and methods in its doc page.

I’m not sure exactly what you’re looking for, though – are you unclear on how you can manipulate the transform matrices?

1 Like

Well they’re TRS-Matrices, like the docs state.
Some pages about matrices:
Transformation Matrix - Definition, Formula, Applications, Examples (cuemath.com)
Transformation matrix - Wikipedia
Spatial Transformation Matrices (brainvoyager.com)

1 Like

Well, a concrete example would be the available built-in shader variables during rendering. Unity already provides those matrices based on the Transform information to the shader. The Transform hierarchy itself is stored as seperate localPosition, localScale and localRotation to describe the local matrix while the “parent” property of the Transform forms the actual hierarchy.