Day 88: Moving Platforms in Unity

Tyler Smallwood
3 min readNov 14, 2021

--

Objective: Get platforms to move to and from a point smoothly.

We will create a system where a platform will move from point A to point B. To make this clean in the Hierarchy we will create a empty Game Object and create a cube inside the empty Game Object. We will have the two points as well.

After setting up the points of where you would like the platform to move to, we will turn the script. In the script we will need a variable to hold each of the target points and one for the current target.

Next we will need to have speed variable to control how fast our platforms will move.

Now will be to move the platform from targetA and targetB. In Update we will check to see if the platform is at the same position as one of the points. Depending on which target the platform is at, we will set the current target to be the next point.

On the platform we will assign the two points to the points in the script on the platform.

Now to move the platform. After setting the target we will move the platform. We will set the platforms position to the Vector3.MoveTowards();

Our platforms will now move but while the player is on the platform we will get some jittering.

To fix this jittering, we will need to set the player as a child to the platform. We do this by using OnTriggerEnter and when we jump off we will need the player to no longer be a child of the platform. We do this by setting the parent to null with OnTriggerExit.

On the platform we will have to Box Colliders and one of them with IsTrigger set to true.

The Box Collider with IsTrigger set to true we will need to raise it a little to register the player.

Now with this all set up we will be able to ride the platform with no jittering.

Thank you for reading and have a wonderful day!!

--

--

Tyler Smallwood
Tyler Smallwood

Written by Tyler Smallwood

I am passonate on learning to program and use Unity to become a skillful Unity Developer

No responses yet