- Home /
Generating a tiled world with roads, possibly using a 2D array? (C#)
So I am wanting to generate a world full of individual tiles. First question; would generating a new mesh per tile work? If so, how could I generate a 100x100 world (or any dimension for that matter) of interconnecting planes?
So lets say I make a 100x100 world of individual meshes. Would I then be able to make a 100x100 2D array and assign each coordinate of that array to a plane tile that has a corresponding coordinate on the map? I want to do this so I can use multiple passes on this array with an algorithm that will assign a prefab building, structure, or terrain to each tile such as a road, office building, house, etc. (Though I have no idea how to do that...). Each prefab would have an ID, so say I want a house prefab at (10,60) on my map, I would take the house ID and assign it to (10,60) in my 2D array. Is that feasible?
I'm wondering all of this because I have searched far and wide and have not found any good ways to generate city streets on a grid based system. I thought of this prefab ID and 2D array thing and it's all I've got to work with now. If I can generate roads, I can maybe generate another 2D array that assigns zones like industrial, business, etc. to different segments of roads and then generate corresponding prefabs in their correct zones.
I doubt much of that made sense, but if you can help whatsoever please do. Also, if you know of any other methods for generating a world with roads that meet my requirements (tiled, roads go north/south/east/west and not diagonal, organic looking) I would greatly appreciate your assistance. Thanks!
Example of the array:
[000000000000000000]
[000000000000000000]
[000000000000000000]
[000000000000000000] //Original empty array
[000000000000000000]
[000000000000000000]
[000000000000000000]
[110000000001000000]
[010000111001000000]
[011110101111111100]
[000011111000000101] // After roads are generated. Road prefabs
[000000010001011111] // (with an ID of 1) would be placed on planes
[000000111111110000] // with corresponding coordinates
[000000000100011000] // (such as (1,7) & (2,7)).
Edit:
I've managed to generate a 2 tri square and can shift it perfectly by one unit. Now I need to work on filling a 2d array with values to place my prefabs. Anyone have any algorithms to run patterns inside 2d arrays?
would generating a new mesh per tile work?
No. Create mesh chunks ins$$anonymous$$d.
If you want more information per tile coordinate than a simple int, string etc. variable can store, then define a custom class that holds that information (like terrain type, zone, inhabitants etc.) and create your 2d array out of this class.
This question is too much for UA so I recommend starting a thread on the forums or search for tutorials on (procedural) mesh generation, there are lots of tutorials for both 2d and 3d ($$anonymous$$inecraft style).
Thanks! I already understand basic mesh generation. I'll head to the forums and start a thread there.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How could I make a Randomly Generated Grid-Based Neighborhood? 2 Answers