Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Connected tiles question

Discussion in 'Scripting' started by InsaneGoblin, Feb 3, 2015.

  1. InsaneGoblin

    InsaneGoblin

    Joined:
    Jun 2, 2013
    Posts:
    239
    Hi there!

    Revamping my tiles skills, and have a question:

    Without directly supplying the code (I just want the theory, want to write the code myself, at least initially), how can I make it so that tiles react to the ones next to them?

    Let me explain with an example:

    There's a dynamic quad tilemap (can be 5x5, 20x15, etc). I click a tile and that tile has an arbitrary value of 3. The ones around it have a value of 2, the ones around the latter have a value of 1.

    Struggling to find an quick and easy (performance-wise, don't mind writing a lot of code) solution without colliders (solved this issue with 4 colliders on each tile, but I feel it's unnecessary) or pathfinding (too much stuff going on, this would drag performance). Can anyone help, please?

    Thanks!

    PS: I would be very greatful for links to guides/tutorials on how to properly work in a tiled environment. Another things I'd like to learn is how to find what GO in an array is the closest to the source (think of a worker that needs to gather wood, and automatically goes to chop the closest tree). Thanks again!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,520
    What you want to do really isn't possible without a little bit of coding to do the heavy lifting.

    Essentially you want to keep track of a grid of cells corresponding to each tile.

    Alternately you can create a graph of nodes representing the tiles, if a grid is too rigid (like if you have different-sized or missing tiles).

    The collider would get you the info of what hit the one tile, which would have some way of knowing where it lies in the graph, and then there would be code to traverse the graph and decide who else is affected nearby, and to update them appropriately.
     
  3. InsaneGoblin

    InsaneGoblin

    Joined:
    Jun 2, 2013
    Posts:
    239
    Would like to resurrect this thread. Got some spare time in my hands and would really like to tackle this issue.

    Can someone point me to a decent tutorial/guide that explains this?

    Thanks!