Anyone knows how to remove the tilemap cell when the mouse clicks on it?

if the player clicks with the mouse

  • get mouse global position
  • get tile at global mouse position
  • set cell of the tile to -1 => delete the tile

In code it would look a bit like this:

# Get Mouse position
var mouse_pos = get_viewport().get_mouse_position()

# Get the tile coordinates at that mouse position
var tile_pos = map_to_local(local_to_map(mouse_pos))

# layer 0, position of tile, -1 means no tile
tilemap.set_cell(0, tile_pos, -1)
2 Likes