Reputation: 33
Can I somehow get information that the player has touched a specific tile located in the resource (tilemap.res)? It is necessary to determine which tile it stands on (for example, on land or in water)
Upvotes: 0
Views: 1432
Reputation: 714
It depends on what kind of behavior you're expecting. There's two major ways to do this:
The exact method to find the tile is TileMap.world_to_map(TileMap.get_cellv(Node2D.position))
--you just need to have the Node2D and the TileMap, and you can get both in the same function using the above two methods.
Technically, you could also procedurally add Area2Ds to the tilemap based on the tiles at various positions using TileMap.get_used_cells_by_id
, making sure that the ID is the one that has the special behavior, then attaching the TileMap to those areas' body/area_entered
and body/area_exited
and using that, but spamming a whole lot of Area2Ds isn't necessary when you can check the tile a Node2D
is on directly.
Upvotes: 1