Skip to main content
‹ Back to Tutorials
Intermediate Unity

Unity Playmaker 2D Platformer - Player Jump and Ground Check

Oct 7, 2021
About this tutorial

In this Unity Playmaker 2D Platformer - Player Jump and Ground Check tutorial, I'll show how you can set up Jump for your character using Playmaker. I'll show how to use both a Swipe Gesture action for Mobile as well as a Get Key Down action for desktop. Then we will use the Add Force 2D action to

Written Guide

This tutorial gives the 2D platformer player a jump — triggered by either a swipe on mobile or the space bar on desktop — plus a raycast ground check so the jump can't be spammed in mid-air. The whole thing is one Playmaker FSM with three states.

Step 1 — Listen for jump input

Add a new FSM to the player and name it Jump. Rename the first state Jump Input — its job is to wait for the player to ask for a jump. Add two input actions side by side so both platforms work: a Swipe Gesture Event set to swipe up for mobile, and a Get Key Down set to the space bar for desktop. Both fire the same custom event, jump, which transitions to a new state named Jump. Supporting both inputs in one state costs nothing and saves you a rework later.

Step 2 — Apply the jump force

In the Jump state, use Add Force 2D on the owner. Set the force mode to Impulse — that applies the push all at once instead of gradually, which is exactly what a jump should feel like. Put the force on the Y axis with a positive value of 5, and leave Every Frame unchecked; if it ran every frame the character would keep accelerating upward like a rocket. Add a finished transition out to a third state.

Step 3 — Add the ground check

Without a check, looping straight back to Jump Input lets the player hammer the space bar and fly. Name the third state Ground Check and add a Raycast 2D action. A raycast is a laser line shot out from the character — here it fires from the center of the player straight down (direction Y of -1). The distance controls how long that line is: the character is about one unit tall, so half of that, 0.5, is the starting guess. When the ray hits something, fire a new event called grounded that transitions back to Jump Input.

Step 4 — Only detect the ground layer

By default the ray detects everything, including the player's own collider. Restrict it with a layer filter: set the filter mask count to 1, create a new layer in the Inspector called Ground, assign that layer to the floor, then select Ground as the layer the raycast can interact with. Now the ray only reports true ground contact.

Step 5 — Tune the ray distance in play mode

On the first test the FSM gets stuck in Ground Check — the 0.5 ray is too short to reach the floor. Here's the practical trick: while the game is running, click and drag the distance field until the line touches ground and the state machine snaps back to Jump Input. For this character that lands at 0.8. Play-mode changes don't save, so stop, type 0.8 into the distance, and test again. Now the character jumps once, can't double-jump in the air, and regains the jump the moment it lands.

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 →