i’ve searched here and answers to no avail. what i’m hoping to achieve is a random level generation much like Diablo and other dungeon crawlers.
i’m going to assume that there are two ways to approach this. either a grid-like system where each “tile” is created and fits on an XbyX grid… the other is similar but using non grid-like tiles.
now, the usual, i’m still noobish and at a loss to how to code this (though i have a bunch of tiles already made that could be used for this.)
what would be the best way to approach this sort of dilemma? i COULD make each level separately but that would be time-consuming and limit the replayability of the game.
use-able in both multiplayer and single-player settings (but for ease of use, multiplayer levels could be made separately so that there isn’t an unfair layout for one or the other teams.
i’m also going to assume that there would need to be some sort of start and end point tileset (like in diablo/torchlight/etc.) so that the system knows what to connect point A and B to.
ideally, i’d like to incorporate a maze like setting so that the player could take a wrong turn and have to backtrack but that could be the next iteration of whatever code is being done.
Choose a start and end point and create a randomly-twisted path between them. Then, for each point on that path, randomly decide whether to branch off or no.
You’d definitely use a grid to define where your path exists already so you don’t crash into it (unless that’s inconsequential), but that’s the basic idea.
Here’s a really basic semi-implementation:
var mainPath : List.<Vector2> = new List.<Vector2>();
var end = new Vector2( /* whatever */ );
var current : Vector2 = new Vector2( /* also whatever */ );
mainPath.Add( current );
while( current != end ) {
if ( Random.value > 0.5 ) { // go right / left
if ( end.x > current.x ) current.x += 1; else if ( end.x < current.x ) current.x -= 1;
} else {
if ( end.y > current.y ) current.y += 1; else if ( end.y < current.y ) current.y -= 1;
}
mainPath.Add( current );
}
for ( var startingPoint : Vector2 in mainPath ) {
if ( Random.value > 0.5 ) {
thisNewBranchLength = Random.Range(1, maxBranchLength );
currentPoint = startingPoint;
nextGridPoint = currentPoint;
var possibleMovements : Vector2[] = [ Vector2.up, Vector2.right, -Vector2.up, -Vector2.right ];
for ( var ix : int = 0; ix < thisNewBranchLength; ix++ ) {
// create a branch of that length
while ( mainPath.Contains( nextGridPoint ) )
nextGridPoint = currentPoint + possibleMovements[ Random.Range(0,3) ];
currentPoint = nextGridPoint;
// update grid
}
}
}
The genre of game you’re thinking about is known as a Roguelike, tracing it’s roots back to original dungeon crawling games that procedurally generate entire levels (and normally feature deep, complicated worlds and permanent death mechanics). Rather than outline my favourite dungeon generator algorithm, I’ll attach a link to the Roguebasin Wiki where there are a tonne of pseudocode pages explaining them. [[/URL]
If you are looking for an existing solution that works with Unity 2017.2 and later, I thought I’d add my (paid) asset that works with Unity’s Tilemap system. It’s called Strata.
Strata is an easy to use procedural toolkit for generating 2D levels which use a combination of hand-authored and procedurally generated content. It works at edit time or at runtime without additional programming. Strata works with Unity’s native 2D Tilemap tools allowing you to hand-author pieces of levels and arrange and combine those pieces in interesting ways.
The design philosophy of Strata is strongly inspired by both classic roguelike dungeon crawler design approaches along with the newer school of action roguelike / roguelite games. To this end, the project contains demos both for a classic top-down roguelike dungeon generator, and a 2D platformer built from a connected chain of handmade rooms. Both serve as good starting points for your own creations.
Programming procedural level generation tools can be complex and difficult, and with Strata, I hope to open the creation of procedural content to artists, level and game designers and other non-programmer creators.