Tilebase at the cell in a tilemap using hexagons/Vector3Int issue

Hi all,

In my hexagon-grid top-down turn-based strategy project, I made the ground using tile palette. Different tiles should have different movement cost, so I am trying to make A* pathfinding project read which tile is placed in each Hex.

I wanted to use Tilemap.GetTile, however, since its only possible parameter is Vector3Int, it does not work well with Hexagons where every other line is offset by 0.5. Furthermore, I am using true hexagons which means the height of a cell is 1.1547 instead of 1.

Is there a way to return the tilebase at CellLocation using Vector3? Or an alternative that would work with (true) hexagons?

Please let me know if you need more information.

It seems like you are working with local/world space positions? If you are, you can convert them to cell positions using Tilemap.LocalToCell or Tilemap.WorldToCell first before using Tilemap.GetTile. You can convert the cell positions back to the local/world space positions with the reverse methods.

1 Like

Thanks! Worked perfectly. I hadn’t realised GetTile calls for cell position rather than world space position and would probably never have realised on my own…