- Home /
How do I create a relatively simple random 2d city grid? (includes image)
I am trying to create a city street grid like this in a two dimensional array (ignore the green parts).
I want to provide the city's width and length in meters and get an int[x,y] array with the values for each coordinate. Each pixel in the image represents a 10mx10m square, which is the smallest subdivision in my map, so for each pixel I would have map[x,y]=1 if there's a street, or a 0 if it's not a street.
For the creation I have two parameters:
int [,] blockDimensions = new int[,] {{300,80},{200,80},{140,80},{120,80}}; // in meters
int[] streetWidths = new int[] {10,20,40}; // in meters
blockDimensions is the standard block dimensions for the city, but obviously the city cannot be a perfect grid with three (or more) different block sizes, which can be horizontal or vertical, which is okay, as no city has a 100% perfect grid. The important thing is that the majority of the blocks have these dimensions and the city map looks realistic. Also, the blocks should not all have the same orientation, the same size can appear horizontally or vertically.
streetWidths is the acceptable street width range, nothing can be wider than this. The smallest value (10) is auxiliary and should randomly split big blocks, not sure how to use it yet.
One more thing, The grid sizes are based on real cities (New York City) and Wikipedia said that they start at the middle of the street. So with 10m units, for a 120x80 block we would have:
111111111111
100000000001
100000000001
100000000001
100000000001
100000000001
100000000001
111111111111
This, attached to another block would create a 2px street between them which is acceptable. But it really doesn't have to be like that, as long as it looks realistic, if it's easier not to include the street widths in the block, I'm fine with it.
Any one knows of an algorithm that I can use as a base to build something like that? I am not expecting a complete solution obviously, but any hints would be appreciated.
Something like this would be perfect as well, although some end blocks would have to be removed to give a more realistic shape (there are no completely square cities):
I honestly think this is too big of a question for Unity Answers. You could try looking into the "After playing $$anonymous$$inecraft..." Thread on the Unity forums for information on random terrain generation, Perlin noise, etc.
@Cherno, thanks, I've already looked into various procedural terrain generation algorithms, but I find them irrelevant. I want to create simple shapes, not randomized terrains.
There's an algorithm that does dungeons though, by creating random rooms and then wiggling them out in each loop, until nothing touches anything else. $$anonymous$$aybe I could use that with some tweaking, but I don't know where to start.
I know this is an old thread but did you ever figure out a solution for this.
Trying to do something similar myself
Your answer
Follow this Question
Related Questions
Galaxy Procedural Generation 1 Answer
Procedural Cylinder Generation 2 Answers
OnValidate changed fields doesnt save after exit the play mode. 1 Answer
How to make a grid and able to place buildings on? 0 Answers
Procedural generation of dungeons with rooms made in the new tile map system? 0 Answers