Skip to main content
‹ Back to Tutorials
Intermediate Unity

Unity Playmaker 2D Platformer - Horizontal Movement X Axis

Oct 3, 2021
About this tutorial

In this Unity Playmaker 2D Platformer - Horizontal Movement X Axis tutorial, I'll show how you can set up a moving your character left and right as well as flipping your character based on the input. This is the beginning of a series of 2D Platformer mechanics using Unity and Playmaker. (to Join m

Written Guide

This tutorial opens the 2D platformer series with the fundamentals: moving the character left and right from keyboard input, and flipping the sprite to face the direction of travel. Two FSMs handle it — one for movement, one for facing — connected by a single global variable.

Step 1 — Use Unity's built-in Horizontal axis

Open Project Settings and look at the Input Manager: Unity ships with predefined axes, including Horizontal, which already maps the A and D keys plus the left and right arrows. Copy that name exactly — the axis is referenced by string, so a typo means silent failure. On the player, add a new FSM named X Move.

Step 2 — Read the axis into a global variable

Add a Get Axis action and paste in Horizontal. Bump the multiplier up so the character moves at a decent clip — tune it to taste. Store the result in a new global variable named x move. Making it global rather than local is deliberate: a second FSM is going to read this same value for the character flip, and globals are how FSMs share data.

Step 3 — Apply it: translate or velocity

There are two ways to use the axis value, and both work. Option one is Translate Position 2D driven by the global x move on the X axis. Option two is Set Velocity 2D — uncheck the vector option and feed x move into X. Either way, place the action below Get Axis (read first, then apply) and check Every Frame on both actions. Test: the character slides left and right on keys or arrows.

Step 4 — Flip the character with scale

The flip trick is scale, not rotation: an X scale of -1 mirrors the sprite to face left, and +1 faces it right again. Add a second FSM on the player named Flip Character with two states, Right and Left. In Right, add a Float Compare on the global x move, every frame: if the value is less than 0 the player is heading left, so fire a new flip left event and transition to the Left state; if it's equal to 0 or greater, fire flip right and stay facing right.

Step 5 — Set the scale in each state

In the Right state, add a Set Scale on the owner with X at positive 1 — no every-frame needed, since the flip happens once on entry and it's done. Copy that action into the Left state and change X to -1. Mirror the Float Compare logic in Left so it fires flip right when x move goes positive again, giving you a clean two-state loop that tracks the movement direction.

Test it

Run right and the character faces right; turn around and the sprite mirrors instantly to face left. That's horizontal movement plus facing in two small FSMs — and the global x move variable is now available for anything else the series builds on top, starting with the jump in the next episode.

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 →