#How would I detect if a tile is in a different tile grid of a larger size?

1 messages · Page 1 of 1 (latest)

frosty raptor
#

I'm sorry, I'm not sure how to explain this. I'm messing around with procedurally generating tilemaps, and I'm trying to recreate what is happening in the first image.
The much smaller, blue grid matches up with the larger red grid. I can get it to work when the two grids are the same size.

When the grids are a different size the second image happens.

This is the code for the detail grid:

private void AddDetails() // gets called when world map has generated
{
    detail.ClearAllTiles();
    for (int x = -20; x < 20; x++)
    {
        for (int y = -20; y < 20; y++)
        {
            if (display.GetTile(new Vector3Int(x, y, 0)) != null) // the red grid
            {
                detail.SetTile(new Vector3Int(x, y, 0), tile); // the blue grid
            }
        }
    }
}

Thanks for helping, if you can

forest karma
#

You need to convert between the two coordinate spaces!

#

Suppose the large grid's cells are exactly twice as large as the small grid's cells

#

You can unambiguously go from the small grid to the large grid by dividing a small-grid coordinate by two and flooring the result to an integer

#

so, for example, these four coordinates would all map to [0,0]:

  • [0,0]
  • [1,0]
  • [0,1]
  • [1,1]
#

going from the large grid to the small grid is a bit more annoying, since there are four possible small cells to choose