Portponky / better-terrain

Terrain plugin for Godot 4
The Unlicense
509 stars 24 forks source link

better-terrain

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.

Example of terrain system in use

Why?

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.

Installation

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:

  1. Either:

    • Clone or download the repo, and copy the addons folder into your Godot project.
    • In Godot's asset library, search for Better Terrain and click download.
  2. In Project settings make sure the plugin is enabled in the Plugins tab.

  3. 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.

Usage in the editor

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).

Usage in code

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...)

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.

Documentation is available in Godot's editor help system, accessed by pressing F1.

Videos

I made some videos on how to use this plugin.

Tutorial videos

Contact

Feel free to report bugs here, or find me (Portponky#6300) on the Godot official discord server. Have fun!