godotprocedural-generation

Tilemap / Autotile / Terrain dependencies / redraw capability in Godot 4


I am working on functionality for destructible, procedural terrain (think Terraria / Starbound) for a game, and in order to make the blocks not look terrible, I have configured a nice auto-tile. See sample tileset below:

Sample Dirt tiles for a simple game project

So far, these work great and tile well enough - they randomly select from the available tiling options etc., however as part of the game mechanics, players will need to be able to remove tiles, so this: Sample terrain block Would become this: Sample terrain block with one block removed

As you can see, it's quite ugly. Ideally the dirt border on top would also get deleted, and the correct autotile would fill in that area, like so:

Desired output of autotile functionality

I've tried looking for various settings such as tile dependencies (to solve the culling of border tiles) or automatic autotile refreshing, but I haven't found anything of either sort. Any kind of programmatic solution I can think of would likely involve calculating all nearby tiles and manually culling / placing border tiles as appropriate, which would likely be catastrophic for performance given how many times this action will be happening.

Any solutions or pointers would be appreciated.


Solution

  • Maybe this might help,
    best I can tell from the video is that you first have to remove the tile using set_cell

    Then have to get all 8 tiles (4 horizontal & vertical + 4 diagonals) surrounding the tile you removed and update those tiles using set_cells_terrain_connect