Howdy.
So I’ve built a random map generator - or to put it in context, a dungeon generator. Every time a new segment is added to the dungeon chain, it picks another one, from corridors, corners, t-juntions and dead ends. Finally finishing when only dead ends are picked.
However, if a set of corners get picked in a row, or a large enough map is generated that it overlaps in even more complicated ways, it gets a bit screwed up. Can anyone think of a way of keeping track of, or somehow stopping it from overlapping on itself?
Thanks
Is the generator based on a grid system? If so, you could use a 2D array of booleans to mark which grid squares have been filled in. Then, you just need to restrict the choice of each new dungeon segment to the segments types that will fit into the available space at the end of the chain.
No, it’s not grid based.
I put in a raycast, to check if stuff was nearby, but there were too many eventualities where it missed.
Here’s the generator code with all ancillory stuff removed, can anyone see a solution?
Oh, right; this piece of code is attached to an empty at the end of each of the segments, so it keeps replicating until only end pieces (which have no empty space) are left.
var tiletogen = 0;
var tile1 : Transform;
var tile2 : Transform;
var tile3 : Transform;
var tile4 : Transform;
function Start () {
yield(WaitForSeconds(1));
tiletogen = Random.Range(1,5);
Debug.Log(tiletogen);
//tile 1 is corridor
//tile 2 is end
//tile 3 is corner - right
//tile 4 is corner - left
if(tiletogen == 1) {
gen1();
}
else if(tiletogen == 2) {
gen2();
}
else if(tiletogen == 3) {
gen3();
}
else if(tiletogen == 4) {
gen4();
}
}
function Update () {
var forward : Vector3 = transform.TransformDirection(Vector3.forward) * 10;
Debug.DrawRay (transform.position, forward, Color.green);
}
function gen1() {
var tile = Instantiate(tile1, transform.position, transform.rotation);
}
function gen2() {
var tile = Instantiate(tile2, transform.position, transform.rotation);
}
function gen3() {
var tile = Instantiate(tile3, transform.position, transform.rotation);
}
function gen4() {
var tile = Instantiate(tile4, transform.position, transform.rotation);
}