Help with Procedural City Generation

Hello! I’m working on a procedurally generated town system and could use some help figuring out the best approach. My game is inspired by games like “A Dusty Trip” or “Dead Rails” , but instead of a vast desert, the environment is a city with buildings on both sides of the road. I already have a system that generates a straight road in segments, and each segment is spaced correctly and placed smoothly. However, I’m having trouble figuring out how to build around that system to generate a believable city. I was also planning to

What I’d like to achieve is a system that spawns buildings alongside the generated road. These buildings should snap to a grid or chunk system (I’m using 90x90 chunks), be randomly selected from a set of prebuilt models, and vary in size—some might span multiple chunks, like 2x1 or 1x2 buildings or more. I also want to make sure they don’t overlap or float into the road, which is currently an issue. I’ve added connector parts like FrontConnector, LeftConnector, and RightConnector to help align buildings to the road segment, but sometimes one chunk is inside the road or it’s off, especially for larger models. I was also planning to add roads and turns but the buildings are a bigger problem as of now.

Right now, the 1x1 buildings work perfectly and spawn properly aligned to the side of the road. I’ve attached two images below showing how the current generation looks with just 1x1 buildings.

image
image

So far, I’ve tried using a chunk occupancy system to check whether space is free before placing a building, and I align them using the connectors mentioned earlier. I also attempted random placement and even tried placing “back buildings” behind the front row to add depth but I can’t seem to think of ways on doing it without breaking the game. I’ve looked into maze or cell-based generation systems as well, but I’m unsure how to make those with my current setup, especially since I’m not an expert at these types of stuff. I’ve checked several posts on the DevForums, but most focus on terrain generation or random biomes rather than ones that focus on cities.

What I’m really struggling with is how to scale this properly: how to handle larger chunks, how to keep generation consistent and clean, and how to eventually include special POIs or randomized events along the way with roads. I’m wondering if I should stick with my current approach or change it to something else.

I’ve also attached a file that includes the current version of my road and building generation system. Feel free to take a look at how it’s working so far. The 1x1 buildings should spawn correctly, I stopped working on bigger buildings as they kept breaking:

Procedural town generation.rbxl (645.9 KB)

Any advice, ways to fix this, or sample approaches would be greatly appreciated. Thanks in advance!

I would highly recommend just starting with a grid system, you need something to start from to figure out what other properties are worthwile. You can make grids that are pretty efficient by indexing a table with the string coordinates:

roadGrid["1,2"] = gridContents

A string describing two numbers is of course always unique, and this method prevents allocating space in the grid system that is just empty.

1 Like

Thank you for the response! I’ll try doing this method :slight_smile: