Terrain plugin for Godot 4's tilemap.
This plugin implements autotile-style terrain system with multiple connections. It works with the existing tilemaps and tilesets alongside Godot 4 features.
Godot 4 has a terrain system built-in to its tilemap node. This system has some tricky behaviors and is tailored towards a very specific usage of tilemaps, rather than a more general case. It's also quite slow, and the API is difficult to use at runtime. There are very large functional gaps caused by the replacement of the Godot 3 autotile system.
better-terrain
is available from Godot's asset library, but the latest version is available here.
To get started with better-terrain
, follow these steps:
Either:
addons
folder into your Godot project.Better Terrain
and click download.In Project settings
make sure the plugin is enabled in the Plugins
tab.
Restart Godot.
Now when you select a tilemap node, a new dock tab called 'Terrains' will show up. Here, you can define terrains and paint with them.
The dock has terrain types on the left, and tiles on the right. At the bottom of the terrain types, there are buttons to add, modify, sort, or remove terrain types. A terrain type has a name, a color, a type, and an optional icon. The four types are:
Along the top, you will find the following buttons:
You may also see a "Clean data" button, which occurs when terrain has data that does not apply to the current tileset shape or offset axis (for example, you set up rectangle terrain then change the tileset to be hexagonal).
The terrain system is usable via code via the BetterTerrain
autoload, which the plugin handles. The editor dock is implemented entirely using this class, so it is fully featured.
To edit terrain at runtime, first you must set terrain into cells, and then you must run an update function for the cells to allow it to pick the best tile for each terrain. This is similar to the API for Godot 3.
To set or get terrain in cells, these functions are available. Terrain types are integer indexes into the list you see in the editor (e.g. the first terrain is 0, the second is 1, etc...)
func set_cell(tm: TileMapLayer, coord: Vector2i, type: int) -> bool
func set_cells(tm: TileMapLayer, coords: Array, type: int) -> bool
func get_cell(tm: TileMapLayer, coord: Vector2i) -> int
Once cell(s) are set, they must be updated. Use one of these functions to run the updates. They also update the neighboring cells, though that can be switched off if desired.
func update_terrain_cells(tm: TileMapLayer, cells: Array, and_surrounding_cells := true) -> void
func update_terrain_cell(tm: TileMapLayer, cell: Vector2i, and_surrounding_cells := true) -> void
func update_terrain_area(tm: TileMapLayer, area: Rect2i, and_surrounding_cells := true) -> void
Documentation is available in Godot's editor help system, accessed by pressing F1.
I made some videos on how to use this plugin.
Feel free to report bugs here, or find me (Portponky#6300) on the Godot official discord server. Have fun!