• 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
1
Question by adriandevera · Jul 10, 2015 at 05:34 PM · mesh3dproceduraltileadjacent

Procedurally Connected Mesh/3d Model Tiles?

On a grid-based game, how would I procedurally determine adjacent objects (North, South,East, West) in an efficient manner?

I already have everything implemented from grid, to grid object placement, to actual object placement. Id like to implement this automatic system rather than having the player ie. select a corner for the building or sidewalk model

Below is a picture to better describe what Im trying to explain:

alt text

I have several 3d model variations of multiple objects from cliffs to paths/fences to buildings. Im aiming to allow players to place an object in runtime where if another of the same object is placed next to it, then depending on the direction a different mesh piece would replace the other.

Think of it as the Cliff system while making a map in starcraft 2 or warcraft 3.

alt text

(Place an object, in this case a cliff, then place another next to it and both will change where the left cliff would have no face on its right side and the right cliff would have nothing on its left face.)

Im trying to do this because allowing objects to simply overlap with one model rather than having multiple variations of the model with different faces not rendered is more ideal. Another example with exactly what I want: alt text

(Web browser Version)

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Cherno · Jul 10, 2015 at 05:46 PM

You have to implement your own tile identification logic. Each tile needs something that identifies it's basic type, such as "hill", "river", "road" and so on. This can be done in several ways, for example a simple int where 0 is clear, 1 is ground, 2 is road, 3 is hill and so on. Or a string that directly describes the type. Or a enum value. Something like that.

Then, when building the mesh, you have to go through each tile, and for each tile, check it's neighboring tiles for their type as well. Based on that information, your code can decide which mesh part to use for the current tile. For example, if the tile at x,y is a hill, and the tile at x+1,y (left neighbor) is ground/clear, then you need a cliff for the tile at x,y. It gets more complicated the more neighbors you have to take into account, of course.

Comment
Add comment · Show 3 · Share
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 adriandevera · Jul 10, 2015 at 05:53 PM 0
Share

Ah okay perfect. I made a rough draft of my own version last week doing exactly what you explained. It works properly and as intended but now a question of what is an efficient way? Ive known people use something like raycasts (which is fine if I place one object at a time and call the method) but this may be an issue if I do a mass placement?

The best way would be to locally check that tile rather than the whole tile map which is what you explained, so now would I use Raycasting (can be costly), forloops (what Im currently using) or do you have another suggestion?

Thanks for the quick and awesome reply by the way!

avatar image Cherno · Jul 10, 2015 at 06:18 PM 0
Share

Raycasting is highly inefficient for this. Take a look a $$anonymous$$inecraft-in-Unity tutorials and how they create the terrain mesh. You declare a two- or three-dimensional array where each element corresponds to one cell of your world. I assume you already do this since you mentioned using loops, which is exactly how you should do it.

avatar image adriandevera · Jul 10, 2015 at 07:31 PM 0
Share

Ah alright, then I suppose the system I have is already as efficient as it is.

Thanks for the advice again!

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

23 People are following this question.

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

Related Questions

How to texture walls in procedurally generated mesh? 1 Answer

Convex Mesh Collider on Procedurally generated mesh does not conform.. 2 Answers

Determining where a mesh triangle faces 1 Answer

Lightmapping and Diablo3-style big-tile levels 0 Answers

Realtime C++ Unity Interaction 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges