2D Tileset Terrain in Godot 4
Intro
As part of the tileset overhaul, Godot 4 replaced autotiles with a new tileset terrain feature. It makes it a bit of a pain to upgrade a tileset based project, but the end result should be a lot better.
Unfortunately, the docs don't yet cover this in detail, so I had to do a bit of trial and error to figure it out.
Setting up the Terrain
For this example, I'm recreating a simple 2x2 tileset autotile, meant to draw clouds/fog.
In godot 3, it would have had a bitmask that looked like:
The tile atlas I'm using for this example is in fact based on this image.
- Set up a standard tilemap/tileset using that image as a tile atlas
- that's also different from godot 3, but the docs are solid on how to do it
- Add a Terrain Set
- Add a Terrain underneath that, and give it a useful name (Fog, in this case)
- set its mode to
Match Corners and Edges
- go to the
Paint
tab of the tileset editor and choose that terrain - click on the tiles to draw the bitmask for each tile
- drawing the bitmask is massively faster in godot 4 - way less clicking around
It ends up being the same general shape directly in the tileset terrain editor. The biggest gotcha here is that it's still a 3x3 bitmask inside each of the tiles, and the only tile with that center bit set is the fully-filled one.
Here's what it looks like:
Drawing with the Terrain
Drawing with the terrain is easy enough at this point! There's a few different options:
- the
Connect Mode
icon will use the fully-filled tile and adjust the surrounding 8 tiles based on you wanting to make larger connected shapes - this is probably the most useful option - the
Path mode
icon will do the same thing but it picks tiles assuming you're trying to draw long and skinny lines.- It doesn't really seem different for my example here, but I assume it's more obvious on the other terrain modes
- select and draw with a specific terrain tile - the editor will use that as a base and draw an appropriate auto shape around it. This is mostly useful for touch ups
Note the eraser
icon at the top; you can toggle that on or off to clear our tiles quickly. I kept forgetting to toggle it back to drawing mode.
Other modes
I haven't tried the other modes yet, but hopefully this guide helps someone out!