Monday 10 July 2017

Project 1: Simple City Generator


Procedural, Grid-Based, City Generator


As an exercise, I decided to create a procedural city generator. It is quite rudimentary, but has some interesting elements that are worth mentioning.

The Unity-built generator works by populating an area with pre-defined (and measured) prefabs (such as specific road segments).

The first stage creates a central junction, which is then extended with randomly selected pieces - to create a random distribution of junction points along a primary 'X'.


After this has been created, the algorithm finds the intersections of all junctions and fills the road layout in accordingly - creating junctions and straight-pieces as necessary.

As you can see, at this point the generator has created a fairly effective (if a bit robotic) road layout. Naturally this creates rectangular spaces between the roads, so by using a box-packing algorithm, the spaces can be neatly populated with building prefabs.

However, in order to make the cityscape a little more interesting, the algorithm random spawns a number of "district nodes" (a point in space with a specific enumerator type attached to it). Each rectangle measures its distances to these nodes and selects from a different pool of building prefabs, based on the type of the node. In short, the city generator creates districts which have a consistent feel - allowing for the creation of residential, industrial, political or other themed sections of the city.


Here you can see the result - clustered buildings of different types forming different districts within the city. (Please excuse the white-box assets - I am not a 3D modeller and have to make do with what I can find / convince friends to make in their free time).



As a final touch, I added invisible, weighted, pathing geometry to the road segments / crossings, and added Oculus Rift support so that the player can explore the city in first person, and meet its denizens (who are designed only to spawn / navigate around the player).


No comments:

Post a Comment