You need to convert the position from global coordinates (which is what you get in a KinematicCollision or KinematicCollision2D such as the one returned by get_slide_collision) to the coordinates of the TileMap.
What I said above can be accomplished like this:
var local_position:Vector2 = tilemap.to_local(position)
However, you also want the position in tiles. Not pixels. Which you could do using the size of a cell:
var local_position:Vector2 = tilemap.to_local(position) var cell_position:Vector2 = local_position/tilemap.cell_size
Or alternatively yet, do it like this:
var local_position:Vector2 = tilemap.to_local(position) var cell_position:Vector2 = tilemap.world_to_map(local_position)
And now you know what world_to_map does and why you would want to use it. There is also a map_to_world that does the opposite transformation.
If I understand correctly you want to remove the tile that your KinematicBody2D collided with. So you are taking the position of the collision. However, the position of the collision is not inside the tile.
To fix that, you can offset the position in the opposite direction of the normal of the collision (i.e. inwards into whatever it collided with):
var tilemap:TileMap = collision.collider as TileMap var local_position:Vector2 = tilemap.to_local(collision.position) var cell_position:Vector2 = tilemap.world_to_map(local_position) cell_position -= collision.normal
Then cell_position should be inside the correct tile.
tilemap.get_cell(position.x, position.y)insideremove_tilereturn the tile you are expecting to modify? I recall different coordinate behavior forset_cellvsset_cellv... could you be pointing it at something other than what you intend? \$\endgroup\$