Table of Contents
Who hasn’t dreamed of creating their own video game? Maybe a small dungeon crawler, with a top-down view, a hero moving through dark rooms filled with monsters, and that magical sense of unpredictability that only a roguelike can offer. If you too, like us, have dreamed at least once of bringing your pixel-art world to life, then you’re in the right place.
In this three-part article series, we’ll guide you step by step through the creation of a simple but complete 2D roguelike developed in Unity, using as our foundation the open-source project 2DRogueTest, freely available on GitHub. Of course, this example isn’t meant to be a commercial game or a visual masterpiece: it’s a concrete example, created to help beginner developers find their way through scripts, prefabs, tilemaps, and gameplay logic.
In this Part 1, we’ll start with project setup, sprite import, and creation of a basic movement system for the player character. Nothing complicated or stressful: everything is explained calmly, with practical examples, existing files, and the idea of having fun while learning.
Ready to take your first steps into your digital dungeon? Then let’s go!
1. Creating the Unity Project
Open Unity Hub and create a new 2D project called 2DRogueTest
. For simplicity, we’ll use the Built-in Render Pipeline, though you can easily adapt it to URP.
Make sure the project has the following initial structure:
1 2 3 4 5 6 |
/Assets /Animations /Prefabs /Scenes /Scripts /Sprites |
These folders already exist in the GitHub repository.
Open the scene /Scenes/SampleScene.unity
, which is the main game scene.
2. Importing Pixel Graphics
In the /Sprites
folder you’ll find the sprites used in the game, including:
character.png
– our player characterenemy.png
– the basic enemytileset.png
– tileset for floors and walls
Unity will import them as Texture Type: Sprite (2D and UI)
. Set the Pixels Per Unit
consistently (e.g., 16 or 32) to maintain pixel-perfect proportions.
In the Sprites.meta
file you’ll find the correct import and slicing settings.
3. Adding the Player
In the project, the main GameObject for the player is found in the prefab /Prefabs/Player.prefab
. It consists of:
- a Sprite Renderer with
character.png
- a
Rigidbody2D
(Body Type: Dynamic) - a
BoxCollider2D
It’s linked to a script called PlayerController.cs
located in /Scripts/PlayerController.cs
.
Here’s an excerpt of the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
public class PlayerController : MonoBehaviour { public float moveSpeed = 5f; private Rigidbody2D rb; private Vector2 movement; void Start() { rb = GetComponent<Rigidbody2D>(); } void Update() { movement.x = Input.GetAxisRaw("Horizontal"); movement.y = Input.GetAxisRaw("Vertical"); } void FixedUpdate() { rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime); } } |
This simple script allows for smooth movement in four directions.
4. Setting Up the Map and Environment
The initial map is built at runtime, but the project includes a static example in the SampleScene
to test movement. The floor and walls are created by manually placing tiles from tileset.png
.
Alternatively, you can import Unity’s 2D Tilemap Editor
package to create maps directly in the editor.
5. Camera and Player Follow
The scene’s main camera uses a script called CameraFollow.cs
found in /Scripts/CameraFollow.cs
. Here’s the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
public class CameraFollow : MonoBehaviour { public Transform target; public float smoothSpeed = 0.125f; public Vector3 offset; void LateUpdate() { Vector3 desiredPosition = target.position + offset; Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed); transform.position = smoothedPosition; } } |
To make the script work, just assign the player’s transform to the target
field.
6. Test and Build
At this point, you can run the SampleScene
, move the character, and verify that everything works. The map is still static, but in the next part we’ll add enemies, AI, and a combat system.
Conclusion
In this first part, we’ve built the foundations: player, movement, map, and camera. Everything is already available in the GitHub project 2DRogueTest. In the next part we’ll focus on enemy AI and combat mechanics.