getting Tile after collision when tile is more then one unit large

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

I am attempting to add ability to collision with tiles that removes the tile when it’s hit. I got it working with tiles, but then when I made the tiles larger (making the titles in the atlas 3x3), and suddenly they aren’t removed anymore. the print_debug still shows it collides.

if (collision.get_collider().get_class() == "TileMap"):
		print_debug("ball hit tilemap")
		var localc = tilemap.to_local(collision.get_position() - collision.get_normal())
		var cell = tilemap.local_to_map(localc)
		tilemap.set_cell(0, cell, -1)

I tried using tilemap.erase_cell(0, cell) instead of set_cell, but got the same result.
Saw error/warning in debugger, though I think that was there when it was working as well.

editor/plugins/tiles/tile_set_editor.cpp:227 - Condition "!tile_set.is_valid()" is true.

EDIT: Added some extra logging:

print_debug("cell=", cell, " cell_data for 'cell'=", tilemap.get_cell_tile_data(0, cell))
print_debug("used cells=",tilemap.get_used_cells(0))

and got

cell=(33, 4) cell_data for 'cell'=<Object#null>
used cells=[(9, 3), (12, 3), (15, 3), (18, 3), (25, 3), (28, 3), (34, 3), (37, 3), (43, 3), (46, 3), (51, 3), (54, 3)]

so now I’m assuming I’m translating to local map coordinates wrong, though not sure why it worked before then.

:bust_in_silhouette: Reply From: jjcard

I found a much easier way. Can use the RID to get the coordinates:


so can then call erase cell with that, which works.

tilemap.erase_cell(0, tilemap.get_coords_for_body_rid(collision.get_collider_rid()))