Skip to main content
‹ Back to Tutorials
Intermediate Unity

Unity Playmaker 2D Platformer - Elevator Moving Platform

Oct 13, 2021
About this tutorial

In this Unity Playmaker 2D Platformer - Elevator Moving Platform tutorial, I'll show how you can set up a moving platform or elevator using Playmaker. We will set up box colliders, triggers and tags to detect the elevator, move the platform up and down, as well as attaching the player to the platfo

Written Guide

This Playmaker tutorial builds a 2D elevator, a moving platform that carries the player up and down between locations. The work splits into two halves: making the platform travel on a loop with a tween, and attaching the player to it so they ride along instead of sliding off. The scene starts with an elevator lift sprite sitting over a hole, ready to be turned into something interactive.

Setting Up Colliders and Tag

The lift needs two colliders. First add a Box Collider sized roughly to the floor level so the player can stand on top of it. Then add a second Box Collider with Is Trigger enabled, which is what detects the player; the solid one supports them while the trigger senses them. Keep the colliders slightly inside the sprite's outer edges so the player actually has to climb onto the platform for it to register. Add a new tag named elevator and apply it to the lift, since the parenting logic later relies on that tag.

Moving the Platform with a Tween

Add a Playmaker FSM to the lift, label it move elevator, and create a state named move up. A Tween Position is an easy way to animate movement. Read the current position, around negative 11 negative 2, and tween to negative 11 positive 2, moving it up four units. Set the easing to In Out Cubic so it starts slow, speeds up, and eases out gently, with a duration of 3 seconds. Add a finished transition to a second state. Copy the tween into a move down state and reverse the target to negative 2, and add a delay of 2 seconds so the elevator pauses at the top before descending. Give the starting state a 2 second delay as well, producing a continuous loop: wait, rise, wait, fall.

Why Parenting Is Needed

Testing at this point shows the platform looping correctly, but the player standing on it does not stay locked to it as it moves. The solution is to parent the player to the elevator while they are on it, then detach when they step off. This is what the elevator tag is for.

Attaching the Player

On the player, create a new FSM named set parent. In its detect elevator state, use a Trigger Event 2D on the owner set to On Trigger Enter colliding with the tag elevator. It sends a set parent event and stores the contacted object in a new variable called parent. The set parent state then runs a Set Parent action, making the player a child of that stored parent game object so it rides along.

Detaching on Exit

Copy the Trigger Event 2D into the set parent state, this time using On Trigger Exit, and send a new detach player event to a detach player state. There, a Detach Children action removes the player from the parent object referenced by the variable, followed by a finished transition back to detect elevator. After this, the player no longer jitters out of place while riding, and stepping off cleanly detaches them, a complete reusable elevator system.

Unity tools by Bliz Studio
Built for our own games — now on the Asset Store

Multi Tag — unlimited hierarchical tags for any GameObject. Hierarchy Pro — style your whole hierarchy with rules. Made by a Unity dev, for Unity devs.

Explore our Unity assets →