Search Unity

Town Generation

Discussion in 'General Discussion' started by ExtremePowers, Jan 24, 2015.

  1. ExtremePowers

    ExtremePowers

    Joined:
    Sep 27, 2013
    Posts:
    28
    I would like to make a procedural town generator, but I have no idea where to start. I can make an area where the town is but I have no idea on how to procedurally place the buildings and crates etc. So my question is can anybody give me a place to start of with the procedural placement?
     
  2. FreeTimeDev

    FreeTimeDev

    Joined:
    Jul 7, 2012
    Posts:
    64
    You should start with having a rough idea on what is going to be procedural. Also, how far apart buildings should be. And how many buildings. Draw a town a few times, different each, and write down how they're similar. Use this list as a basis. Make note of how they're different -- these are the attributes you want to try to change every time.

    If you want absolutely everything to be procedural you should probably decide how much space in your game you need. Do a check to see if there's enough room (Physicsoverlapsphere). Then, if I were to do it, I'd start in the middle of the town and start where there's enough room.

    Decide what objects can be in the middle (Or, your first object). (A well, a cross roads sign, etc).
    Decide what's going to be around that object. Everytime you want to spawn something do a check to see if something is there. You'll probably want to check limits (only 1 post office, only one inn) so that you can't get too crazy. After you spawn something, "move" on to that object, and spawn centrally from there.
    So, if you spawn a well in the middle and later spawn a post office, sheriffs office, and a saloon, move to the post office. Do a check from the post office's point of view and do another physics overlap sphere check. Spawn something else (Houses, stores, etc). Do this for every building.

    Make bools/ints/Lists to check if you have the minimum number of buildings spawned, and you don't have too many of something.


    That's the basics, I think. You'll have to make sure the buildings spawn on top of the ground, and not in it or floating above it. You'll probably have to work on spawning a common road system so the buildings also spawn facing the correct way, or a way that makes sense.
     
  3. delinx32

    delinx32

    Joined:
    Apr 20, 2012
    Posts:
    417
    The most common approaches tend to use a hybrid approach. Define a set of rules, this could be a set of .txt files containing different methods of laying out portions of towns, with pre positioned possible places for things. Randomly pick the rules and join them in a coherent manner, ie ruleset 1 has a connecting point at position x,y, and ruleset 2 has a connecting point at position x1, y1. Line them up in this manner and continue until you've satisfied a growth threshhold.

    Place the "important" things at positions defined in the ruleset, fill in the unimportant things as sparsely or densely as you desire.

    I tried for along time to get coherent noise to generate natural looking features and eventually decided to go with the hybrid approach. My results are much better than they were using pure noise. Here is an example from my map gen visualization. Each colored section indicates a section of the world, white is the "water plane" where water can possibly flow, blue is the water. The lakes/sections are created from about 4 different shape files that i join together to satisfy a growth threshhold, while maintaining connectivity. Its early work, but you can see how the structures are both random, and coherent.

    Procedural content is really hard. Anyone can toss together a noise algorithm and create something using noise, but coming up with something that makes sense is difficult because pure randomness doesn't exist in the world, and humans (users) aren't dumb enough to ignore the divergence from order. Everything is the product of rules: rocks, rivers, valleys, etc are all created by natural forces. Towns are laid out by intelligent minds to suit a certain purpose. You will have a hard time getting pure randomness to imitate intelligence in a satisfying manner, so it's important to insert your own intelligence to force order to the chaos. You get to play god when doing pure procedural content, but remember that a god needs to have a plan or you end up with a cow hanging out on the roof of your general store.
     

    Attached Files:

  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860


    Totally happens
     
  5. Deon-Cadme

    Deon-Cadme

    Joined:
    Sep 10, 2013
    Posts:
    288
    @BoredMormon - Awesome post! :D

    @ExtremePowers - Procedural systems are all about math and rule systems... you have to literally define a rule that tell the game when it is allowed to make a road, where it should make that road, how it should make that road. If roads might end up crossing each others paths (depends on how you make the system) what should the system do then? The rules also must have rules that avoid a road that goes straight into buildings... this is just a simplified road example but that is how everything from the terrain to houses, roads, plants, trees, npcs are placed in the end... a ton of math, rules and systems that interact with each other in a controlled way.
     
  6. ExtremePowers

    ExtremePowers

    Joined:
    Sep 27, 2013
    Posts:
    28
    Could I make a grid system for the town, and then make the buildings have height and width units in this grid, and keep 1 unit between each building?
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    How about you do what everyone else does when they ask questions like this? They try it out. It's called confidence and without that you will never be able to become self sufficient in game development. You will always end up hitting a wall with no answers. One person can answer it properly: you.

    What you suggested was good.
     
    ExtremePowers likes this.
  8. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    It's what I did in Zombie Invasion of Eggland, most newer towns and cities are built on a grid.



    The problem with procedural content is navigation, Unity's navmesh system did not deal well with procedural content. I ended up using A* Pathfinding project to allow for dynamic navigation in a procedural system.
     
  9. ExtremePowers

    ExtremePowers

    Joined:
    Sep 27, 2013
    Posts:
    28
    I am already using A*, because my terrain is procedurally generated. So that isn't going to be a problem :)
     
  10. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    What are you using to generate the terrain?
     
  11. ExtremePowers

    ExtremePowers

    Joined:
    Sep 27, 2013
    Posts:
    28
    Currently a fractal Perlin noise
     
  12. ostrich160

    ostrich160

    Joined:
    Feb 28, 2012
    Posts:
    679
    That could cause issues. Wouldnt stop you, it would just cause issues. The issues being that the terrain isnt flat, so your buildings will have to sense the angle they are built at on a hill and all that
     
  13. ExtremePowers

    ExtremePowers

    Joined:
    Sep 27, 2013
    Posts:
    28
    The terrain is pretty flat except for the mountains, but I can prevent the city from being on the mountain. :)
     
    ostrich160 likes this.