Godot Version
Godot 4.4
Question
Hello, I am working on making an object to behave as a drill that can dig through tiles in a TileMap. I’m relatively new and very novice in understanding. Currently, I’m using the unique name of my tilemap in the level as a variable in the gd script attached to the drill object.
I am able to get this working great when coming in from the top side and right side, using a Raycast2d (set up below), but when coming in from the left side or bottom side, it doesn’t take the cell away like I was hoping. What’s weird is I can get it to show the coordinates and print like the collision is working fine, it just wont remove the cell.
I have tried using set_cell() and end up with the same issue, and functionality as when I use erase_cell. I’ve also tried to set this up in a gd script attached to the tile map so it would maybe be a more direct way to erase the cell, but I am stuck with the same problem. So I went back to having it all take place in the drill script so I have nothing scripted to the tile map and is half working as before. Do you know if I am missing an important step here for removing the cells or am I stuck with top and right side functionality? Here is the code I have for the drill:
func _physics_process(delta: float) -> void:
_drilled_here()
func _drilled_here():
if ray_cast_2d.is_colliding():
var collision_point = ray_cast_2d.get_collision_point()
var collider = ray_cast_2d.get_collider()
if collider:
if collider.is_in_group("MudWall"):
var tile_pos = mid.to_local(collision_point)
var tile_spot = mid.local_to_map(tile_pos)
mid.erase_cell(tile_spot)
mid is what I named the layer
Thank you for reading.
Not sure if this helps but I found that the source id of the tile is coming in as -1 when colliding from the left side or bottom and what I found says that means it thinks the tile is empty but I’m not sure why.