Reputation: 31
In Godot 4.0 I am attempting to add ability to detect collision with tiles that removes the tile when it's hit. I got it working with 1x1 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)
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.
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 I'm wondering if it needs it to be the exact 'center' coordinates for the tile? Not sure how to fix that...
Upvotes: 0
Views: 571
Reputation: 31
I found a much easier way. Can use the RID to get the coordinates:
tilemap.get_coords_for_body_rid(collision.get_collider_rid())
so can then call erase cell with that, which works.
tilemap.erase_cell(0, tilemap.get_coords_for_body_rid(collision.get_collider_rid()))
Upvotes: 2