Procedural Generation in 2D Systems (Unity)

Exploring algorithmic dungeon generation for replayable level design.

Unity Demo Download

Demo Video

Overview

This project explored procedural generation methods to create dynamic, replayable dungeon layouts for 2D games. The study compared corridor-first and room-first algorithms, focusing on maintaining logical door connections, spawn areas, and pacing through automated spatial analysis.

My Role:

  • Implemented corridor-first and room-first algorithms

  • Designed door connectivity and spawn logic

  • Built BFS-based difficulty depth assignment

Tools Used

  • Unity (C#)

  • Tilemap System

  • BFS Pathfinding & Depth Metrics

  • Gizmos Debug Visualizer

Prototype Setup

The prototype generated connected dungeons using corridor and room prefabs. Each generation pass analyzed connectivity, room adjacency, and door overlap to ensure seamless traversal. BFS was used to assign depth tiers for difficulty scaling, allowing controlled enemy and loot distribution.

Methodology

To evaluate generation quality, multiple test iterations were conducted with variable map sizes, room densities, and connection thresholds. Metrics such as path connectivity, traversal distance, and room overlap were measured to ensure balance between randomness and structure.

  • Key Methods

    • Corridor-first and Room-first generation

    • BFS-based room depth scoring

    • AABB overlap avoidance

    • Portal door linking validation

Seed Input

Room Generation

Corridor Linking

BFS Depth Analysis

Results

The procedural generation framework produced 100% traversable maps in most cases, maintaining valid connections between all rooms. BFS-based depth analysis effectively balanced pacing and difficulty, showing consistent control over enemy and loot placement zones.

Key Statistics

  • 100% connected dungeon success (post-validation)

  • <5% overlap rate (AABB collision)

  • Scalable structure up to 50 rooms

Takeaways and Conclusion

Procedural generation can successfully create replayable, balanced level structures when guided by spatial heuristics. The combination of deterministic BFS scoring with randomized layout input allows both structure and unpredictability — essential traits for modern roguelike and action games.

Lessons Learned

  1. Structural constraints improve playability without reducing variety.

  2. BFS depth systems enhance pacing and progression.

  3. Hybrid approaches (semi-random seeding) yield the best results for balanced gameplay.