Confused about local / global positions

Hi,

I got a bit confused now about local / global position informations in Unity.

A.) transform.localPosition (local) and
B.) transform.position (global)
describe the same points in different coordinate systems (A. in local space, B. in world space).

→ Hence:
Converting transform.localPosition from local space to world space (transform.TransformPoint()) should give me transform.position
and
converting transform.position from world to local space (transform.InverseTransformPoint()) should give me transform.localPosition.

This is not the case and now I am confused.

Would someone please make this clear to me?

Thank you.

A (hopefully) less confusing definition of the positions:

transform.localPosition is the position of the GameObject with respect to its parent object.
transform.position is the position of the GameObject with respect to the root.

Within local space of a GameObject, the center (or pivot) is always (0, 0, 0). To express position and localPosition using TransformPoint:

// these are mathematical equalities, not actual code

transform.position = transform.TransformPoint(Vector3(0,0,0))

Vector3(0,0,0) = transform.InverseTransformPoint(transform.position)

transform.position =
transform.parent.TransformPoint(transform.localPosition)

transform.localPosition = transform.parent.InverseTransformPoint(transform.position)

As you can see, local position can only be found using the transform of its parent.

5 Likes

Understood :slight_smile:

Thank you for pointing it out to me.