Topic was automatically imported from the old Question2Answer platform.
Asked By
mrmtonio
i have this character and a tilemap, I want to make him able to dig tunnels and mine the tiles (sort of like terraria).
But, considering code, how would I go about doing that? What are the variables that able me to manipulate the tiles individually?Is it even possible doing it with a tilemap?
Looking at TileMap it’s pretty easy to achieve. First of all, get tile that player is digging, you will need X and Y coordinate of that tile. Then use set_cell method to change that tile to other that represents hole.
About collision… I don’t know if Godot will update collision when tile is changed or if you have to do that manually. In case it’s up to you, take a look at update_bitmask_area. Passing Vector2 with tile coordinates should update collision for that tile. Honestly that’s my guess, can’t test it.
Changing the tile to -1 (empty) or another id without collider should work directly, it may take a couple of frames to update collisions, though.
If using autotiling or navigation, some extra steps will be needed to refresh the tilemap.