Skip to main content
‹ Back to Tutorials
Intermediate Unity

Unity 2D Playmaker - Simple Player Movement Tutorial

Sep 1, 2021
About this tutorial

In this Unity 2D Playmaker Simple Player Movement tutorial, I'll take a look at setting up a simple Unity 2D Playmaker movement for a 2D Character for a 2D Platformer or other type of 2D Game. I'll show how to use the Get Axis action to gather key input data, then use that with the Translate 2D ac

Written Guide

This tutorial builds complete 2D player movement in Playmaker: the character walks left and right with the arrow or A/D keys, flips to face the direction of travel, and switches between idle and walk animations automatically. It's a three-part setup — animator triggers, a movement FSM, and a flip FSM — and each piece stays small and readable.

Prepare the animator

The character comes with Idle and Walk animations. In the Animator, create transitions both ways between them and add two triggers named idle and walk. On each transition, turn off exit time so the switch happens instantly, and set the condition to the matching trigger. These triggers are what Playmaker will fire later — the animator itself doesn't need any other logic.

Read input and move

Create an empty Game Manager object with a child called Player Movement, and attach an FSM named Player Movement (naming matters once you have several FSMs). Unity's Input Manager (Edit > Project Settings > Input Manager) already defines a Horizontal axis covering the arrow keys and A/D, so copy that name and use it in a Get Axis action. Set the multiplier to 3 — 1 is very slow — and store the result in a new global variable called player speed. It's global because other systems will want this value later. Then add Translate Position 2D below Get Axis (get the value first, then use it), targeting the zombie player. Playmaker warns the character needs a Rigidbody 2D — click the fix button to add one, then set its gravity scale to 0 so the character doesn't fall. Point the translate's X axis at player speed and the character now slides back and forth with input.

Flip the sprite with scale

Facing direction is just X scale: a scale of 1 faces right, -1 faces left. Add a second FSM named Flip Player. In its first state, add two Get Key Down actions — right arrow sends a flip right event, left arrow sends flip left — and add both transitions. Ctrl-drag off to create Flip Right and Flip Left states. In each, use Set Scale on the player (uncheck the variable option) with X set to 1 or -1 respectively. Then add Get Key Up in each flip state so releasing the key transitions to an Idle state, which finishes back to the key-down listener. That loop keeps the FSM responsive to every press.

Fire the animation triggers

Finally, connect movement to animation. In Flip Right and Flip Left, add Set Animator Trigger targeting the character, and pick the walk trigger from the browse (three-dot) icon — move this action to the top of the stack so it fires first. In the Idle state, fire the idle trigger the same way. Press play: the character walks, flips, and swaps between idle and walk animations exactly as the state machine dictates.

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 →