- Home /
How to spawn random buildings
Noob here trying to figure out Unity...
So I need a way to make slightly random buildings appear (different roof combinations, etc.) and with certain boundaries on where they spawn (not more than X units away from Building A) This is not for a background, so it needs collision.
Any ideas?
Thanks for the help, guys. In case you were wondering, I'm making a clone of Canabalt.
Answer by Atnas1010 · Nov 04, 2010 at 01:32 AM
Make the different building elements in some modeling software.
Instantiate them randomly with scripts.
Or build the city manually, and accept that it is always the same.
Answer by Loius · Nov 04, 2010 at 03:28 AM
The particular functions you'll want to investigate are
Instantiate( Resources.Load("AResource") )
Random.value
Answer by QueenMab051 · Nov 04, 2010 at 02:56 AM
I agree with Atnas. Your best bet would be creating the buildings and roofs as seperate models in a modeling program like 3ds Max (which you can get a free 30-day trial of), importing them into your Unity project, then using scripts to randomly select and spawn said models.
Answer by Herman-Tulleken · Nov 04, 2010 at 06:58 AM
A very simple solution might be to use a jittered grid for spawning buildings, especially if they are roughly the same size. See this link for information:
http://umbcgaim.wordpress.com/2010/06/17/distributing-stuff/
And here is an interesting paper on random point generation (which could be helpful for spawning buildings too):
http://jenny.cartography.ch/pdf/2010_Jenny_etal_PointPatternSynthesis.pdf
And this could be helpful for generating non-regular grids:
http://gram.cs.mcgill.ca/papers/rudzicz-08-iterated.pdf
Here is some more information on procedural city generation which might find helpful. (It might be overkill for what you are trying, but the ideas are interesting and you could probably simplify or adapt it for your needs):
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.91.8713&rep=rep1&type=pdf
http://ccl.northwestern.edu/papers/ProceduralCityMod.pdf
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.92.5961&rep=rep1&type=pdf
Answer by jasperstocker · Apr 04, 2014 at 02:30 AM
Check out my asset BuildR for generating Buildings at runtime or in the editor.