Skip to main content
‹ Back to Tutorials
Intermediate Unity

Unity 3D and Playmaker - Puzzle Character Movement with Limits using Floats and Float Compare

Apr 18, 2021
About this tutorial

In this tutorial, I'll show how to set up a puzzle character movement. I'll use Set position and a Float Variable and then Compare Float to set limits on player position. Also check out How to Make a Bounce Game Series https://bit.ly/39HIYBU. //TIMESTAMPS 0:00 Introduction 0:25 Environment Using

Written Guide

This demo builds grid-based puzzle movement in Playmaker: a 2D character stepping in half-unit increments across a 3D board, fenced in by float comparisons so it can never walk off the edge. The same pattern fits sokoban-likes, match games, or anything tile-based.

Step 1 — The scene and a camera trick

The whole environment is primitive shapes: cube mountains, sphere clouds, candy-cane models with a wrapped texture, a plane for the board with squished cubes as tiles, and a 2D sprite character on a cube base — proof you don't need fancy assets to stage a puzzle game. The tip worth stealing: frame the shot you want in the scene view, select the camera, and press Cmd+Shift+F (Ctrl on PC) to snap the camera to your current view. Repeat until it's right, then fine-tune with field of view.

Step 2 — Four directions, four states

An FSM named Player Movement (label your FSMs — more will likely join it) listens with four Get Key Down actions: up arrow sends move back, down sends move forward, plus move left and move right. Each event drags out to its own state, and every state gets a FINISHED transition returning to the listener.

Step 3 — Why Set Position alone fails

The first attempt — Set Position with a hardcoded -0.5 on Z — moves the character exactly once and never again, because a hardcoded position is absolute: every press sets the same spot. The fix is to track position in variables. Create two floats, z position and x position (floats, not ints, because the grid steps by 0.5). Each move state then does a Float Add of plus or minus 0.5 to the right variable, followed by Set Position driven by that variable. Now every press accumulates another step.

Step 4 — Fence the board with Float Compare

Unlimited adds walk the character straight off the board, so a Float Compare state sits between the listener and each move state. For forward (negative Z, board edge at -1): equal to -1 stops movement, less than -1 stops, greater than -1 continues to the move state. Move back mirrors it against +1 — equal or greater stops, less continues. Left and right repeat the pattern against x position. Each compare routes stop movement straight back to the listener, so a blocked press simply does nothing.

Step 5 — Debugging the copy-paste

Building left/right by copying the forward/back states introduced exactly the bugs you'd expect, and the video fixes them on camera: an empty move state with no actions pasted in, Float Adds still pointing at z position instead of x, Set Position filling the wrong axis (set the unused axis to None), and a compare still reading the Z variable. The lesson is practical — when duplicating FSM states, audit every variable reference and axis field, because the structure copies perfectly and the details don't. Once corrected, the character steps cleanly around the board and stops dead at every edge.

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 →