- Home /
BSP Tree for dungeons generation, HELP!
Hi,
I've been trying to implement the principles on this article in Unity: http://www.roguebasin.com/index.php?title=Basic_BSP_Dungeon_generation
The code for the class is here: http://pastebin.com/myC3YpM1
The result for only parsing left rooms is here: http://imgur.com/f63BSRv,Ve4Ac0P#0
The result for only parsing the right rooms is here: http://imgur.com/f63BSRv,Ve4Ac0P#1
At first I tried to parse every leafs and implement the whole thing. I quickly found myself in debugging hell. So I decided to start by always splitting on the same axis at half the size for every cut. That way I could tell if something was going wrong.
It would appear I have a problem for my rightRooms as you can see on the result image. We can clearly see that there is a problem when it goes deeper than 2 cuts and start to take too much space an overlap with other cuts.
Debug.Logs for the rightRooms:
http://imgur.com/4fdsIIW,ChYxkTO#0
http://imgur.com/4fdsIIW,ChYxkTO#1
I would really appreciate any help I can get. I tried looking up more on BSP Trees but the only thing I could find is not related to dungeons generation.
Thanks in advance.
After a quick code review, shouldn't
this.leftRoom = new BSPRoom(this.start, new Vector2(split, this.end.y));
actually be
this.leftRoom = new BSPRoom(this.start, new Vector2(start.x+split, this.end.y));
@Jamora hmm how could I have missed that... After adding your mod I could remove the "width/height +=" in the DrawFloor.
Result so far: http://newbiverse.com/unity/bsp.html
Thanks again :D
Answer by Savage_Newb · Mar 12, 2014 at 11:12 PM
I made progress testing certain things out. I decided not to "render" the leftRooms and then I was just left with 1 cube being displayed and it was in the proper size, which lead me to believe that it was actually the leftRooms that were not being rendered properly.
I removed the Mathf.Abs in the function DrawFloor and added the following:
if (width < 0) {
width += this.start.x;
}
if (height < 0) {
height += this.start.y;
}
After that I re-enabled the render of both rooms and also the parsing of both rooms and I got some much better results without any overlapping. If I put the random axis cut everything is also okay. But when I cut sections at random sizes I get some missing sections.
So still a few bugs but i'm progressing :)
That can be a lot of work man! We have a full "procedural castle" generator we built up for a client, it can take man-months of work. BTW a very simple improvement to that algorithm, just, simply, randomly add about three (in the example) connections between adjacent rooms; it just mixes it up a bit. Good luck!
Your answer
Follow this Question
Related Questions
2D Tilemap room prefabs for dungeon generation. 0 Answers
How would I change my procedurally generated map change cells if it detects cells are around it? 0 Answers
Procedural generation of dungeons with rooms made in the new tile map system? 0 Answers
Procedural Random Walk Dungeon Generator? 2 Answers
creating a mesh procedurally 4 Answers