# TransformPoint and InverseTransformPoint: Moving Platform Logic

I'm studying the code of the Unity 2D sidescroller and am having difficulty understanding the logic behind the API function TransformPoint. I posted a similar question before, and while the answer received lead me to understanding a great deal more, I'm still not quite there yet.

The relevant code attached to the main character is as follows:

``````var newGlobalPlatformPoint = activePlatform.TransformPoint(activeLocalPlatformPoint);
activeLocalPlatformPoint = activePlatform.InverseTransformPoint (transform.position);
activeGlobalPlatformPoint = transform.position;
var moveDistance = (newGlobalPlatformPoint - activeGlobalPlatformPoint);
transform.position = transform.position + moveDistance;

``````

What precisely is TransformPoint doing here? The reference says that it transforms from local to world space. But transform.position is already in world space coordinates according to the API reference, and activeGlobalPlatform point is set to the transform of the main character.

So couldn't you just code the following:

``````moveDistance = (activePlatform.transform.position - transform.position);

``````

Also, subtracting Vector3 values subtracts all axes correct? So if the player is standing on the edge of the platform at (1,2,0) and the platform is beneath him at (2,2,0), wouldn't this move the player horizontally each frame? I'm more than happy with any links to reference pages that I somehow missed. I'm looking for a thorough explanation of these functions or simply for someone to point out some key obvious thing that I've missed.

Perhaps there is something about the Transform class in general, and World and Local space that I am missing.

What precisely is TransformPoint doing here? The reference says that it transforms from local to world space. But transform.position is already in world space coordinates according to the API reference, and activeGlobalPlatform point is set to the transform of the main character.

Right, but TransformPoint() is never applied to transform.position or activeGlobalPlatformPoint.

So couldn't you just code the following:

moveDistance = (activePlatform.transform.position - transform.position);

activePlatform.position and activePlatform.TransformPoint(activeLocalPlatformPoint) are only the same if activeLocalPlatformPoint is the zero vector, which won't necessarily be the case. So no, that wouldn't be equivalent in general.

Also, subtracting Vector3 values subtracts all axes correct?

Correct - it is an element-wise subtraction. That is:

``````(x1, y1, z1) - (x2, y2, z2) = (x1 - x2, y1 - y2, z1 - z2)

``````

Is the code you posted actual code from the tutorial? I ask because there's at least one syntax error (missing semicolon, which I assume is a syntax error in UnityScript), and also because there seems to be some redundant and/or out-of-place code there.