top of page

Procedural City Generator

 

This project is my experiment into generating (& populating) a cityscape at runtime.

The project first generates a road layout, then defines, categorizes and populates 'building sites'.

After which, a navmesh is generated and NPCs begin to spawn around the player - navigating to random destination nodes via pavements and crossings. No jaywalking!

I am continually tinkering with this project, so I've posted some captioned images of the various development stages (and will continue to do so).

 

Also, see below for a step-through of the generation process.

 

Please click an image for details.

DEVELOPMENT

Days 1-3

Days 1-3

The early stage of this project was getting the road layout to generate successfully. This is now one of the simplest steps in the process.

Days 3-4

Days 3-4

This shows the early packing technique (there are some brighter buildings, where overlaps have occurred). This was refined for the next stage.

Day 4 - continued

Day 4 - continued

Here you can see the much improved packing algorithm at work. This algorithm evaluates each grassy area between roads, and populates it with a number of buildings sufficient to fill the space.

Day 5

Day 5

As a further refinement, I added some new assets (created by Lewis Markey of Triple Ox Games LLP). These offer a much improved Skyline, but also offered an interesting direction to take the project. The Generator now has building density settings, for more sparse cities.

Day 6+

Day 6+

At its current stage, the generator will define Sectors amongst the building spaces of the city, and assign types to these sectors. it then performs distance checks to determine which pool of buildings to generate the buildings in that location from. As I receive more assets, I will be expanding the types of sector the generator can spawn.

Day 6+

Day 6+

As you can see in this image, this project is also Oculus Rift compatible, with a first person mode. As you can also see, the city is populated with NPCs, who will also cross the road at crossings to get to their destinations. There's still a lot of refinement and planning to be done, but I have many plans for the AI in this project.

STEP-THROUGH

Step 1

Step 1

The root junction is created - this is the origin for the rest of the generation system, and also the parent transform (for those familiar with Unity).

Step 2

Step 2

Roads of random lengths are added each axis of the root junction, with crossroads added at random intervals (though never adjacent to other crossroads). This is fundamental layout generated, the next step is one of duplication.

Step 3

Step 3

The Roads are duplicated from the relevant axes of the core road layout, and moved to be in line with each of the crossroads.

Step 3.5

Step 3.5

The spaces are then filled with crossroads, and the road layout is complete.

Step 4

Step 4

Building sites are generated (the green quadrilaterals), and then assigned district types - which determine which buildings can be spawned there.

Step 5

Step 5

The city is born! Building sites are populated with appropriate building models for their district type, and are packed in to the sites via the packing algorithm.

Step 5 - continued.

Step 5 - continued.

Here you can see the packing algorithm's work a little more closely. A plan for the future of this project is to procedurally generate the buildings themselves, and thus alleviate the need for a packing algorithm, but that is a long term goal at this stage.

Step 6

Step 6

The navmesh is generated, and the city (or the area around the player) is populated with traffic law-abiding NPCs.

bottom of page