Search Unity

Randomly generating roads and buildings?Best way/most optimized/easiest

Discussion in 'General Discussion' started by NutellaDaddy, Jun 21, 2014.

  1. NutellaDaddy

    NutellaDaddy

    Joined:
    Oct 22, 2013
    Posts:
    288
    I am planning on randomly generating a town with roads.

    I don't know if I could just randomly generate the buildings and have the roads set ,but there would be buildings of different sizes and main buildings that are larger with parking lots and other such stuff. I would need these roads to all fit together correctly and accomodate (can't spell that word) for larger buildings. I could make the buildings generate with their parking lots and roads around them. I could use splines for the roads? There are so many things I could do ,but I don't know which would be best. If I had pre set roads than I would have to have the larger more important buildings in the same spot. What do you think. I really need some feedback.

    Random generation really gives the game the replay value that a lot of people look for. Do you think the same old town would get boring eventually? Well enough with the questions I can't wait to hear what you guys have to say.

    If you have any questions for me to get more detailed on what I want in a final working system just ask. I don't need any script or anything like that. I just want tips, ideas, and past solutions for this problem...or goal. Thank you for any response!
     
  2. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    You'll probably find it easier to plant roads down first, then generate building based on block constraints afterward. The hardest thing would be to try to make more organic maps where you have to route around terrain and not lock cities into a pure grid layout.
     
    NutellaDaddy likes this.
  3. NomadKing

    NomadKing

    Joined:
    Feb 11, 2010
    Posts:
    1,462
    It's worth taking a look at the Subversion dev blog (scroll down and start at the bottom). In the end they put the game on hold, but did some pretty nice things with their city generation - maybe you can find a few ideas there!
     
    NutellaDaddy likes this.
  4. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    2,640
    On the same terrain (assuming a non level terrain)? If you generate a road grid first it would be easier to generate the terrain it lays on. Best method to generate a town I thought of is to create a style and then build lego block type chunks using powers of..1, 2, 4, 8, 16 and then combos of length and width of these squares to generate rect shaped facades. Some are bases or street level with entranceways and various window combos. Then a plethora of midlevels that can be mid level story stacking facades and can be stacked to make towers. Then a series of ledge cappings for creating a level on which further stories of smaller footprints can be stacked. Then a series of penthouse caps, the level right below a roof which can be as decorative as the base facades. Finally a series of rooftops.

    You then "look" at the generated road grid and determine the areas dimensions per block and track the vectors of the sides of the road per block edge for building base alignment. By using a set of rules for distance between building footprints using a minmax range you lay down the footprint bases, orienting entrance facades to align parallel to road edge vectors. If the terrain is sloped you then make a second set of determinations as to how many units a buildings side can be over so many degrees of rise or fall before it cuts too far into the facade..

    Once the footprint base facades have been instantiated from the pool of building blocks you can start mid level story stacking. The rule would be that it cannot be larger than the building block below. It can be smaller than the level just below it as long as it is a ledge capping. As you stack you can also mix up the sizes as long as combined length and width do not exceed the previous level's footprint.

    Finally you cap it with a penthouse decorative level cap and then the roofing cap. By adjusting minmax ranges and randomizing things like level stacking count using basic rules as the levels stack an entire range of buildings can be generated and placed to look well planned. The next thing to handle would be materials and textures. By properly UV mapping the building facades to handle tiled textures a range of texture maps for various brick, wood, stone, what-have-you can be assigned at stacking level generation time using rules..such as if a midlevel stacking block then use the facade shader the level below uses if it too is a mid level stacking block. Decorative elements per stacking block can be added in multiple styles and turned on or off based on rules, such as if the base uses such-and-such deco then all subsequent stackers use the same class of deco.

    Obviously you can extend the rules based on what you determine to be best for the types of towns you want to construct and create other rules like how far offset the building facade is from the edge of the roadways. You then set a dozen or two variables or randomly generate the numbers and wango tango... you have a boom town.

    HTH
     
  5. NutellaDaddy

    NutellaDaddy

    Joined:
    Oct 22, 2013
    Posts:
    288
    All these ideas are great guys! Thanks for the response.
     
  6. Windexglow2

    Windexglow2

    Joined:
    Sep 23, 2012
    Posts:
    90
    Even if you randomize a town, it'll get old. The more factors that hide repetition (especially between maps) is important, even it it causes a few bad apples.