How to set up a tile in a tilemap to detect the player or another object?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By atarias1

I would like to create a chess-like game board, and so far I have created a tile grid the player can navigate. But I would like to make it so each individual tile can detect the player, and depending on which tile the player is in a different event could occur. How should I go about setting this up?

Thanks for the help!

:bust_in_silhouette: Reply From: njamster

Instead of letting the TileMap detect where the player is, let the player detect on which tile they stand. Something like this should work:

var cell = $TileMap.world_to_map($Player.global_position)
var tile_id = $TileMap.get_cellv(cell)
match tile_id:
        print("Trigger Event A")
        print("Trigger Event B")