Skip to main content

2D games

There is no separate "2D mode": a 2D game is the same world seen from the side, with a few settings that keep everything in one flat plane. The 2D Platformer template has all of it set up; this page explains each piece so you can build your own.

The 2D Platformer level in the editor
The 2D Platformer level in the editor

The pieces​

  1. A side camera. Select the Camera object and set its projection to Orthographic (no perspective: things far away are not smaller). Size is half the height of the view in meters. Put the camera in front of the level (for example Z = 10) looking straight at it, and add Camera follow with Look at target off so it follows the hero without turning. Offset X pushes the view ahead of the hero. Switch on Use limits and set the box of your level so the camera stops at its edges.
  2. Everything in one plane. Give physics bodies Freeze Z (Physics body card) so they cannot drift toward or away from the camera. Static things such as tilemaps need nothing.
  3. A hero that moves left and right. Add the Platformer behavior and switch on Side view.
  4. Sprites for the pictures and a tilemap for the level.
  5. Parallax layers for the background: hills and clouds that scroll slower than the level (see Parallax).

Freeze position​

On a dynamic Physics body, Freeze X / Y / Z stop the body from moving along that axis, like Unity's Constraints → Freeze Position. For a side view freeze Z. It also works from scripts: component("rigidbody").freezeZ = true.

Together with Don't tip over (which stops it from rotating), a body then slides along the X–Y plane only.

card rigidbody freeze

Platformer: Side view​

With Side view on, the Platformer uses only left and right (the joystick's x, or ←/→ and A/D) and moves along the world X axis, whatever the camera does. Up/down and Camera relative are ignored.

For a sprite, the Platformer also:

  • flips the sprite to face the way it walks. Draw your character facing right; going left turns on Flip X;
  • plays animations by name while Animate is on: Idle when standing, Walk (or Run) when moving, Sprint when fast, Jump going up, Fall going down. A name the sprite lacks is skipped (a missing Jump falls back to Fall and the other way round), and the sprite keeps what it was playing.
card platformer sideview

Make the animations in the sprite editor and name them exactly like that (names are not case-sensitive). The same names play for anything that walks with Move to position, for example a patrolling enemy: it flips to face where it walks and plays Walk (Idle when it stops).

Side view also works with a 3D model hero: the model turns to face left or right and plays its own clips.

One-way platforms and ladders​

  • A one-way platform can be jumped up through and stood on. Mark platform tiles ⬆ One-way in a tilemap (the setting is per tile number: every cell with that tile follows), or switch on One-way platform on a static object's Collider. To drop down through one, press Down and jump (Side view).
  • A ladder is made of tiles marked 🪜 Climbable (or an object tagged ladder). Switch on Climb on the Platformer. If the hero's sprite has an animation named Climb, it plays while climbing and pauses when you stop.

Moving platforms​

Put the Moving platform behavior on an object with a Collider: it slides between its start and a distance you set, pauses at each end, and carries whatever stands on it. A small tilemap of three one-way platform tiles makes a good one; the 2D Platformer template has one over the wide gap.

Ropes, bridges and cars​

Joints tie physics bodies together: a rope bridge of planks on Hinge joints, a platform swinging on a hinge, a spinner turned by a hinge motor, a car on two Wheel (2D) joints driven by the joystick. See Joints.

Lights and shadows​

A dark cave lit by torches, a night street under lamps: add Global Light 2D and Spot Light 2D objects and Shadow Caster 2D components. See 2D lights.

Pixel art​

For crisp pixel art on every screen, add a Pixel Perfect Camera to the camera: it draws each art pixel as a whole number of screen pixels and snaps the camera to them. See Pixel Perfect Camera.

Characters with bones​

Instead of drawing every pose, draw a character once, put bones in it and animate the bones: a Sprite Skin bends the picture, Timelines played by an Animator move the bones, and IK 2D makes hands and feet reach for things. See 2D Animation (bones).

Build a level​

Paint it with a tilemap (use auto tiles so the edges and corners fit by themselves): grass and earth for the ground, a few wooden tiles for stepping stones, and gaps for the player to jump. For rolling hills and round islands, draw the ground along a curve with a Sprite Shape. Put pickups, enemies and the goal on top as sprites. Falling off the bottom is an event: Player y < −8 → Restart scene (the template does this).

Try it​

Start a project from the 2D Platformer template, play it, then open Logic to see how it works. Change the jump strength, add a gap, or paint a new stretch of ground.