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.