Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by teomaragakis · Apr 26, 2014 at 09:13 AM · gridproceduralgenerationcity

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).

simple city grid

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):

alt text

testgrid.png (6.5 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cherno · Apr 26, 2014 at 12:32 PM 0
Share

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.

After playing $$anonymous$$ecraft...

avatar image teomaragakis · Apr 26, 2014 at 12:36 PM 0
Share

@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.

avatar image Hybrid1969 · Aug 20, 2014 at 12:21 PM 0
Share

I know this is an old thread but did you ever figure out a solution for this.

Trying to do something similar myself

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges