2.5D Platformer — #5 Moving Platforms

Objective: Create modular platforms that move between two points

Jean-Noel Seneque
3 min readOct 15, 2021

The project is at the stage now where we can introduction moving platforms. What we need are platforms that move left and right and up and down. Both are the same moving platform with two additional transform positions that ping pongs between.

What do we need? Two points, reference to these two points and logic that moves the platform and switches its direction when it arrives at a point.

For this, I create an empty game object and name it MovingPlatform. I reset its position and duplicate an existing platform, make it a child of the MovingPlatform and then create two Empty game objects and name them Point A and Point B.

I then give Point A and Point B an icon so I can easily see them in the Scene View.

I am going to create a new material to help distinguish a normal platform compared to a moving platform.

Next, let's create a MovingPlatform script to implement its behaviour, drag it onto the platform (not MovingPlatform). Turn the MovingPlatform as a prefab.

In the script, let’s create references to the points and the speed of the platform.

When the game starts, I pick Point B to be the position the platform move towards.

Now that we have the position to move towards, let’s do the movement. We detect when it arrives at that location and swap to Point A and so on.

If I was to move the player onto the platform in its current state, the platform will move away from the player. I would have to move to follow it which is not the user experience we want. We want the player to follow the platform automatically and to achieve this we need to parent the player to the platform only when it is touching the platform.

We need to create a second collider that acts as a trigger zone to detect when the player is on the platform.

In the script, we want to make use of the OnTriggerEnter and if it is the player, make the platforms the player’s parent and when it leaves, set the parent to null

If you enjoyed reading this article give me a Clap, also if you would like to see more, “Follow” me, so you may be notified of future releases. You may also send me a message if you need any further help.

Do you have a project in mind that you need help with, I’m available!

--

--

Jean-Noel Seneque

A Data & Analytics Consultant who is expanding into developing experiences in XR, Enterprise and Gaming space using Unity www.jeannoelseneque.com