Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by Spracky · Apr 24, 2016 at 07:31 AM · c#prefabsarraysprocedural generationrandom gen

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?

Comment
Add comment · Show 2
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 24, 2016 at 09:01 PM 1
Share

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

avatar image Spracky Cherno · Apr 24, 2016 at 09:07 PM 0
Share

Thanks! I already understand basic mesh generation. I'll head to the forums and start a thread there.

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

6 People are following this question.

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

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

Trouble instantiating an Array of Prefabs 1 Answer

Basic object creation in arrays! Syntax error! 1 Answer


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