godotterraintilesets

Using Godot autotiles to place multiple tiles, where one is random and the other is determined by the autotile scheme


I am using Godot autotiles to create levels, and I would like to be able to place grass on top of other grass (like how Minecraft has a grass block, and then on top of the grass there are things like flowers and grass). I already have a full terrain set as well as well as the grass, and grass variants(such as flowers), I just need to know how to implement ruleset of "if outside facing grass tile, add additional grass plant on top." I am also planning to use whatever method is given to me to also add leaves to trees, or rock debris on top of stone, I am just using grass as the example. If possible having multiple layers for this would also be nice but I don't know if that's possible or not.

I have tried manually placing the additional grass, however this solution takes far to long to preform for even a single level, as the grass is multi directional(slopes have their own grass sprite, side facing stuff has its own grass etc etc).

Patterns seem promising however I can't find any documentation on how to use them in an autotile(maybe I'm missing something here?)

I have also looked into a few autotile/terrain plugins but none of them seem to document this kind of behavior.

I have also looked into coding my own plugin or procedural autotile ruleset by extending the built in tilemap node. However, as I am working on a game jam, I don't want to waste an extraordinary amount of time doing that if there is already a built in way to do this.


Solution

  • The TileMap system had a lot of changes in Godot 4, and the documentation has not cached up.

    Yes, you can do layers in the TileMap in the Inspector. But you can't make rules for autotiling that span multiple layers. And no, patterns do not do autotiling.


    It is possible to have randomness in autotiling. This might be sufficient for your goals. It is something like this:

    With that you can have autotiles that have random tiles when you paint them. So you can have a grass tile, and a grass tile with flowers and have Godot pick randomly.


    Now, if you need to do this with multiple layers, then try using the scatter tool instead.

    In the TileMap panel, in the Tiles tab there will be a tool that looks like a dice with the tooltip "Place Random Tile", this will place tiles from your selection at random (including the chance of no tile, controlled by the scattering value that appears when the tool is selected).

    You can use this to - for example - have grass on the first layer, and then draw flowers randomly on a second layer.


    I suppose you could make a script that iterates over one of the layers of your TileMap and populates a second layer at random.

    Use get_used_rect to get the area over which you need to iterate.

    To read the terrain of a tile you need to use get_cell_tile_data, which gives you a TileData object that has a terrain property.

    And the set_cell method can take the layer, the position, and the id of what you want to place.

    You can then come up with your rules for what tile id to place on the second layer depending on the terrain of the first layer.