I'm trying to understand the code for the moving platform support in the Unity side-scroller tutorial.
The relevant code 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;
As I understand it the reason this code exists is because the character controller will not automatically react to a moving collider.
So basically we are subtracted the player's position form the active platform's position in World Space. My understanding is that this should move the character along with the platform.
If the platform is at say (0,1,0) and the player is standing on top of it at (0,2,0) then move distance should equal (0,-1,0) correct? This would move the player's position downward just by standing on the platform.
Here is where I get lost in the logic:
If the platform moves up to (0,2,0) and the player is at (0,2,0) then moveDistance = 0. The purpose of the code as I understand it is to move the player, so his World Space coordinate wouldn't automatically move, and thus be (0,2,0) at this point.
My question is simply this: How does this move the player relative to the moving platform?