GameDevHQ Crash Course #27 Moving 2D Platforms
Now that we have the basic movements done, lets add a different platform type.
This time lets add a moving platform.
First we copy one of our static platforms, change the colour so we know that it is something different, then we need some destinations for the platform to go, for now we will make an up and down destination so it cycles between up and down.
Then we will need to put some code together so it goes between all the points we have for the object
in this case we are limiting our movement to 2 destinations, so when it gets to point A it then goes to point B and vice versa. Using a normal update method gets us a stuttering movement when the player is on the platform, we fix that by changing the update method to FixedUpdate, this limits the amount of times the update method is called per second to smooth out our movement here as we don’t have the player and platform moving at alternate intervals, but we have another issue, the player is not ‘stuck’ to the platform per say we slide off when the platform moves left or right, so we need a way of anchoring the player to the platform while they are grounded to the platform.
With this we have childed the player to the platform, that way when they platform moves the player moves the same amount while it is touching it, so when it jumps we remove it from the parenting to free it from the movement of the platform.