In this video, you will learn how to make a simple moving platform, which will parent your player every time you land on it. The platform will be moved according to waypoints, which will be created as empty game objects that will only contain transform component.
The platform will be a child object of the main platform whose position is set to zero. The child platform can have any value, but the parent platform needs to have zero position, because otherwise the position of the child platform will also become zero. The platform can be created in this way: make a simple cube object, then add waypoints, which are the empty objects. If you are wondering where are the waypoints, you can see them in the second image:
Now when you have set the platform, you need a simple script. To make the platform move, you need the movement speed value, the platform waypoints and the index value. The detection of waypoints will be done through for-loops, that are important for bringing the platform into action.
Lastly, you don’t want your player to lose its character controller when you move away from the platform. There is a quick fix for this situation!
There are issues when it comes to parenting your player, especially if your player is a character controller. It does not stick to the platform when the character controller is enabled. Make sure that there is one more collider attached, that will be set to Is Trigger.
To fix the platform parent issue, you need to make sure that the collider of the platform will be turned on only when the player is on ground; otherwise it will be turned off when the player is jumping. The platform will revert its collider after two seconds. You will need to check if the player touches the collider.
Leave a Reply