Framework 1: Moving Platform

Adding some dynamics to your platforms

Simon Truong
3 min readOct 18, 2021

--

The next feature which we will add from our checklist is moving platforms. Moving platforms are a staple in platformer games, and adding one in this game would suit it perfectly.

Preparing the Moving Platform:

Setting up the moving platform is very similar to working with the player ledge climbing. We will need two empty game objects which will be the position place holders for the targets. The platform is then going to traverse between these two targets creating the modular movement.

This is the setup you should have per moving platform

Next we need to create a box collider on the Mobile Platform which has the setting “is Trigger” check on. This collider will help later on to allow the Player character become a child object of the moving platform so the player can be moved with the Platform. Therefore the collider needs to be a tad higher than the actual platform surface.

This is how the Box collider is set up.

Scripting the Movement:

Create a new C# script and named it “Platform Behavior” and attach the script to the Mobile platform object. (make sure it isn’t the parent object but the actual platform itself, the one with the box colliders)

Inside the script we are going to create a basic switch which tells the mobile platform to move between the two targets. Create a Serialized Field that will contain the two targets, then have another serialized field containing a the speed variable. Finally a private Transform named Target.

We are going to keep the Start method and within the function we are going to convert the Target to Target A.

Next we are going to use “Fixed Update” instead of the regular Update function because this will give the Player a more stable refresh per frame and won’t cause any jittery movement. Inside the Fixed Update we are going to create the switch statement which allows the platform to ping pong back and forth.

Finally we are going to make the player a child object of the platform so that the platform can carry the player, otherwise the player will be left behind (staying in place) while the platform moves. For this, we will need two trigger functions, On Trigger Enter and On Trigger Exit.

Save and return back to Unity, Now whenever the player makes contact with this special moving platform, the player shall be taken for a ride.

The Platform with the ability to move back and forth.

--

--

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.