How to Make a 2D Top Down Game in Unity (With C# Code)

By Arron R.11 min read
Here’s how to make a 2D top down game in Unity: start a Universal 2D project, paint levels on layered Tilemaps, give the player a Rigidbody2D with zero gravity

Learning how to make a 2D top down game in Unity comes down to getting four systems right: player movement, the tile world, collisions and the camera. Get those working in an empty scene and you have the skeleton of a Zelda-like, a twin-stick shooter or a farming sim. This guide covers each system with working C# code, points out the mistakes that trip up most beginners, and shows where Sorceress fits when you’d rather spend your evenings on design than on boilerplate and pixel pushing.

What is a 2D top down game?

A top-down game shows the world from above, so the player moves freely on two axes: left and right on X, up and down on Y. Nothing pulls the character toward a floor, and that’s the big mechanical difference from a platformer. Classic examples include early Zelda games, Pokémon-style RPGs and arena shooters. Browser battle royales use the same view: ZombsRoyale.io pairs simple 2D graphics with a top-down perspective on a large shared map.

You’ll see a few terms over and over:

  • Sprite: a 2D image drawn in the game world, such as the player, a coin or a tree.
  • Sprite sheet: one image that holds many sprites or animation frames in a grid. Unity slices it into separate pieces.
  • Tileset: a sheet of small square images (grass, wall, water edge) designed to snap together on a grid.
  • Tilemap: Unity’s grid component. You paint tiles onto it to build a level.
  • Rigidbody2D: the component that hands an object to Unity’s 2D physics system so it can collide with walls.

Unity is a cross-platform engine from Unity Technologies, first released in 2005, and its 2D tooling is mature: Tilemaps, sprite slicing, 2D physics and 2D lights. A game engine is the framework that handles rendering, physics, input and audio, so you only write the rules of your game. That’s why figuring out how to make a 2D top down game in Unity takes surprisingly little code. Most of the work is setting things up correctly in the editor.

How to make a 2D top down game in Unity: project setup

1. Install Unity and create a 2D project

Install the Unity Hub, add a recent editor version, then create a new project from a 2D template. In Unity 6 the usual pick is Universal 2D. It uses the Universal Render Pipeline (URP) with the 2D Renderer and comes with the Tilemap and Sprite packages. Choose it unless a tutorial you’re following needs the built-in pipeline.

2. Organise the project

Create folders for Art, Tiles, Scripts, Prefabs and Scenes on day one. It feels fussy, but a top-down game generates dozens of tile assets quickly, and a clean structure saves you from digging through the Project window later.

3. Import your sprites correctly

Drag your character sheet and tileset into the Art folder. Then select each one and check these settings in the Inspector:

  • Texture Type: Sprite (2D and UI).
  • Sprite Mode: Multiple for sheets. Then open the Sprite Editor and slice by cell size.
  • Pixels Per Unit: match your tile size. For 16×16 pixel tiles, use 16 so one tile equals one Unity unit.
  • Filter Mode: Point (no filter) for pixel art. Any other setting makes sprites look blurry.
  • Compression: None for small pixel-art sheets, so colours don’t smear.

4. Add the packages you need

Open the Package Manager, check that the Input System package is installed, then add Cinemachine for the follow camera. That’s the whole toolkit. Everything else in this guide is built into Unity.

Diagram of sprite import settings for a pixel-art tileset in a 2D Unity project
Match Pixels Per Unit to your tile size and use Point filtering so pixel art stays crisp.

Player movement in C# for a top-down game

Create an empty GameObject called Player and add a Sprite Renderer with your idle frame. Then add a Rigidbody2D and a CapsuleCollider2D. On the Rigidbody2D, set Gravity Scale to 0, tick Freeze Rotation Z and set Interpolate to Interpolate for smooth motion. Shrink the collider so it covers only the character’s feet. In a top-down view the feet are what bump into walls, and a full-body collider makes the player catch on every doorway.

Unity scripts are written in C#. Create PlayerMovement.cs in your Scripts folder and attach it to the Player:

using UnityEngine;
using UnityEngine.InputSystem;

[RequireComponent(typeof(Rigidbody2D))]
public class PlayerMovement : MonoBehaviour
{
    [SerializeField] float moveSpeed = 5f;
    [SerializeField] Animator animator; // optional

    Rigidbody2D rb;
    InputAction moveAction;
    Vector2 moveInput;

    void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
        rb.gravityScale = 0f;
        rb.freezeRotation = true;

        moveAction = new InputAction("Move", InputActionType.Value);
        moveAction.AddCompositeBinding("2DVector")
            .With("Up", "<Keyboard>/w")
            .With("Down", "<Keyboard>/s")
            .With("Left", "<Keyboard>/a")
            .With("Right", "<Keyboard>/d");
        moveAction.AddCompositeBinding("2DVector")
            .With("Up", "<Keyboard>/upArrow")
            .With("Down", "<Keyboard>/downArrow")
            .With("Left", "<Keyboard>/leftArrow")
            .With("Right", "<Keyboard>/rightArrow");
        moveAction.AddBinding("<Gamepad>/leftStick");
    }

    void OnEnable() => moveAction.Enable();
    void OnDisable() => moveAction.Disable();
    void OnDestroy() => moveAction.Dispose();

    void Update()
    {
        moveInput = Vector2.ClampMagnitude(moveAction.ReadValue<Vector2>(), 1f);

        if (animator != null)
        {
            animator.SetFloat("Speed", moveInput.sqrMagnitude);
            if (moveInput != Vector2.zero)
            {
                animator.SetFloat("MoveX", moveInput.x);
                animator.SetFloat("MoveY", moveInput.y);
            }
        }
    }

    void FixedUpdate()
    {
        rb.MovePosition(rb.position + moveInput * moveSpeed * Time.fixedDeltaTime);
    }
}

Three details matter here. Input is read in Update, which runs every frame, while movement happens in FixedUpdate, which runs in step with the physics engine. Moving through MovePosition instead of setting transform.position means Unity checks collisions along the way, so the player stops at walls rather than passing through them. And clamping the input vector keeps diagonal movement from being faster than straight movement, a bug players spot within seconds.

If Unity reports that the Input System isn’t enabled, open Project Settings → Player and set Active Input Handling to Input System Package (or Both).

Adding walk animations

Create an Animator Controller and add a blend tree set to 2D Simple Directional, driven by MoveX and MoveY. Put one walk clip at each of the four directions: (0, 1), (0, −1), (−1, 0) and (1, 0). Build a matching idle blend tree, then switch between the two with transitions on the Speed parameter. The script only updates MoveX and MoveY while the player is moving, so the character keeps facing its last direction when it stops. Players notice small touches like that.

Building levels with Tilemaps, colliders and a follow camera

Paint the world with Tilemaps

Choose GameObject → 2D Object → Tilemap → Rectangular. Unity creates a Grid with one Tilemap child. Add two more Tilemaps under the same Grid and name the three of them Ground, Walls and Decor. Open Window → 2D → Tile Palette, create a new palette and drag your sliced tileset into it. Unity turns each slice into a tile asset. Now select the Ground layer and paint floors, then switch to Walls and paint everything the player shouldn’t walk through.

Separate layers are what keep a top-down level manageable. Only Walls needs collision, you can hide Decor while testing, and you can redraw floors without touching a single wall. This layering is the part of building a 2D top down game in Unity that pays off most as levels grow.

Make walls solid

Select the Walls Tilemap and add a Tilemap Collider 2D. On its own, it creates one collider shape per tile, which is wasteful and can snag the player on the seams between tiles. Also add a Composite Collider 2D. Unity adds a Rigidbody2D along with it, and you should set that body to Static. Then tell the Tilemap Collider to feed into the composite: tick Used By Composite in older versions, or set Composite Operation to Merge in Unity 6. The wall tiles now merge into a few smooth outlines.

Follow the player with Cinemachine

From the Cinemachine menu, create a 2D camera and set its tracking target to the Player. A little damping makes the follow feel soft instead of rigid. To stop the camera from showing empty space past the map edge, add a Confiner 2D extension and give it a PolygonCollider2D drawn around the level bounds. For pixel art, add a Pixel Perfect Camera to the main camera so sprites don’t shimmer as they move.

Fix the draw order

Top-down games fake depth. A character standing north of a tree should be drawn behind it, and a character standing south of it should be drawn in front. To get this, tell Unity to sort sprites by their Y position. With URP’s 2D Renderer, open the Renderer 2D Data asset and set Transparency Sort Mode to Custom Axis with the value (0, 1, 0). In the built-in pipeline the same setting is under Project Settings → Graphics. Next, put each character sprite’s pivot at its feet and set the Sprite Renderer’s Sprite Sort Point to Pivot. For tall wall tiles that need to sort against characters, set the Tilemap Renderer’s Mode to Individual. Use Sorting Layers (Ground, Characters, Overhead) for things that should always draw on top, such as roofs and treetops.

Layered Tilemaps with wall colliders, Y-axis sorting and a follow camera in a top-down level
Separate Ground, Walls and Decor Tilemaps, collide only on Walls, and sort sprites by Y to fake depth.

Where do the sprites and tiles come from?

Art is where most solo top-down projects stall. Even a small prototype needs a lot of it: a player with idle and walk cycles in four directions, a couple of enemies, a tileset with edges and corners, props and UI. Free asset packs rarely match each other in style, and drawing everything yourself is slow when you’re still finding out whether the game is fun.

Whatever route you choose, lock in one perspective first. Most top-down art uses a three-quarter view, where you see both the front and the top of objects. A few games use a strict overhead view. If you mix them, the world looks broken right away.

Sorceress covers the art side in the browser:

  • Auto-Sprite v2 (Pro) creates game-ready 2D sprites, including characters, items and effects, in any art style. It uses a three-step flow that starts with generating a character.
  • Tileset Forge (Pro) turns AI art into game-ready tilesets. You generate tiles inside the tool, and any tile can go into Tile Studio for Corridor Key background removal and seamless tiling.
  • 3D to 2D (Pro) renders a 3D character, object or animation into a pixel-perfect 2D sprite sheet from any camera angle. That makes it a neat way to get a consistent high top-down angle for every direction.

If you already drive your Unity project with a coding agent such as Cursor, Claude Code or Codex, the Sorceress API gives that agent one key it can use to generate sprites, 3D models, rigs, animation, music and SFX. Import the results with the same settings from the setup section: Pixels Per Unit matched to your tile size, Point filtering, and no compression for pixel art.

A faster route: prototype the game in WizardGenie

Unity is a solid choice if you want its editor, its asset ecosystem and C# skills that transfer to other jobs. But as you’ve seen, there’s real setup work before anything is playable. If your goal is a game jam entry, or simply finding out whether an idea is fun, there’s a shorter path.

WizardGenie is the AI-native game engine at the heart of Sorceress. You describe the game you want, and WizardGenie writes it, runs it and iterates on it in real time. It runs on the web with nothing to install, and it also comes as a Windows desktop app with an auto-updater that adds native file access and longer agent sessions. It works with the leading AI coding models, and you can switch between them freely using your own API key.

This is vibe coding applied to games: you steer with plain language and judge the result by playing it rather than reading every line. Here’s a worked example of a first prompt for the same game this guide builds in Unity:

“Make a top-down dungeon game. The player is a knight who moves in eight directions with WASD or the arrow keys, with no extra speed on diagonals. Walls block movement. Three slimes wander and chase the player when they get within five tiles. The camera follows the player smoothly. Touching a slime costs one of three hearts, shown in the top-left corner.”

Play the result, then iterate one sentence at a time:

  1. “Slimes get stuck on corners. Make them steer around walls.”
  2. “Add a sword swipe on Space with a short cooldown.”
  3. “Draw trees in front of the knight when the knight is north of them.”
  4. “Add a locked door that opens when the player picks up a key.”

Each of those would be an editor session in Unity. Here, each one is a message. From there you have two honest options. Keep building in WizardGenie, then export the build and host it wherever you like. Or treat the prototype as a living design document: once you know the loop is fun, rebuild it in Unity with the steps above, already knowing exactly which systems the game needs. Either way, you don’t spend a week on how to make a 2D top down game in Unity before finding out whether the idea works. The WizardGenie overview explains the engine in more depth.

Common mistakes when making a top-down game in Unity

  • Leaving gravity on. The player drifts off the bottom of the screen. Set Gravity Scale to 0 on every top-down Rigidbody2D.
  • Moving the transform directly. Writing to transform.position skips physics, so fast objects pass through walls. Use MovePosition or velocity.
  • Unclamped diagonal input. Diagonals end up faster than straight movement. Clamp or normalise the input vector.
  • Blurry pixel art. This is almost always Bilinear filtering or compression on import. Switch to Point and None.
  • Mismatched Pixels Per Unit. Characters come out tiny or huge next to tiles. Use the same value for every asset.
  • Colliders on the floor layer. Only the Walls Tilemap needs a collider, and it should feed a composite.
  • Full-body colliders. The player snags on doorways. Keep colliders at the feet.
  • Ignoring sort order until late. Set up Y-axis sorting early, before you have fifty props to fix.
  • Too much scope. Start with one room, one enemy and one item. A finished small game teaches more than an abandoned RPG.

The workflow at a glance

Here is the full pipeline in one place, with the Sorceress shortcut for each stage:

StageIn UnitySorceress shortcut
Prototype the ideaSet up the editor, scenes and scripts by handDescribe the game in WizardGenie and play it in real time
CharactersSlice sheets, build Animator blend treesAuto-Sprite v2 or 3D to 2D for sprite sheets
LevelsLayered Tilemaps and the Tile PaletteTileset Forge for game-ready tilesets
MovementRigidbody2D plus the C# script aboveOne-sentence prompts in WizardGenie
CollisionsTilemap Collider 2D merged by a compositeAsk WizardGenie for wall collision
Camera and depthCinemachine, Confiner 2D, Y-axis sortingAsk for a smooth follow camera and Y-sorting

The same four systems carry over to other engines too. To make a 2D game in Godot, you’d use a CharacterBody2D for the player and TileMap nodes for the world, and the ideas don’t change. Once you understand how to make a 2D top down game in Unity, you understand top-down games in general. For the full set of art, audio and engine tools, browse the Sorceress tools guide, and when your top-down prototype grows into something bigger, the guide to making an RPG picks up from here.

Frequently Asked Questions

Is there a simple tutorial for creating a 2D top-down game in Unity?

Yes. Create a project from the Universal 2D template and import your sprites with the right Pixels Per Unit and Point filtering. Paint Ground and Walls Tilemaps, give the player a Rigidbody2D with Gravity Scale 0 and a C# script that moves it with MovePosition, add a Tilemap Collider 2D to the walls, then add a Cinemachine follow camera. Once that works, you have a playable top-down skeleton you can build any genre on.

Does Unity use C++ or Python?

Neither, for game code. Unity games are scripted in C#, so your movement, enemies and UI logic are all C# classes attached to GameObjects. The engine core itself is written in C++, but you never touch it in normal development. Python appears only in some editor automation and pipeline tools, not in gameplay scripting. If you already know Java or JavaScript, C# syntax will feel familiar quickly.

Is Unity 18+?

Unity is a game engine, not a game, so it has no age rating of its own. The rating of anything you build depends on that game’s content. Creating a Unity account means agreeing to Unity’s terms, and those set their own age requirements, so younger learners should read the current terms with a parent or guardian before signing up. The editor itself contains no mature content.

Is 32 GB RAM enough for Unity?

For a 2D top-down game, 32 GB is comfortably more than enough. 2D projects with Tilemaps and sprite sheets are light on memory compared with large 3D scenes, high-resolution textures or heavy lighting bakes. Memory pressure usually comes from running the editor, a browser, an IDE and other tools at once, and 32 GB covers that easily. A fast SSD speeds up imports and script recompiles more noticeably than extra RAM.

Should I make my 2D top-down game in Unity or Godot?

Both handle top-down 2D well. Unity gives you C#, a large asset ecosystem and a huge library of tutorials. Godot is lightweight, open source, and its CharacterBody2D and TileMap nodes cover the same movement and level-building ideas with GDScript or C#. The four core systems (movement, tiles, collisions, camera) are the same in either engine, so the skills transfer. Pick the one whose workflow you enjoy and finish a small game.

Sources

  1. ZombsRoyale.io — Wikipedia
  2. Unity (game engine) — Wikipedia
  3. Game engine — Wikipedia
  4. Vibe coding — Wikipedia
Written by Arron R.·2,563 words·11 min read

Related posts