Portponky / better-terrain

Terrain plugin for Godot 4
The Unlicense
433 stars 21 forks source link

Tiles 1 away from a corner don't connect correctly #64

Closed Wcubed closed 6 months ago

Wcubed commented 6 months ago

First of all, I'd like to thank you for the awesome plugin! This is exactly how I expected the terrain tiling in Godot 4 to work :)

I noticed something weird. In my setup I have two terrain types: grass and water.

The terrain has a rectangular lake, inside a large patch of grass: image The strange thing is that the tiles near the corners (marked with the red arrows) will randomly pick between a straight transition piece, or a corner piece. When filling the lake repeatedly with "shuffle" enabled, I get different arrangements of these tiles. The rest of the tiles stay rock solid, even the actual corner pieces.

This is my terrain setup: Connection rules for grass: image Connection rules for water: image

From the connection rules I would assume that the only valid pieces for near the corners, would be the straight transition pieces. Am I misunderstanding how the connection rules function? Or is there a bug in this specific situation.

Godot version: v4.2.1 Plugin version: v1.0


EDIT

As an experiment, I changed the connection rules to the following: image image

Now the lake does work, but it seems to get confused at the ends of this T shaped water section. It always fills those with full land, while according to the connections I would assume the straight transition pieces fit perfectly. image

Thanks again for the great work!

Portponky commented 6 months ago

Hi,

For the first example, let's have a look at the top left corner, and the tile to the right of it. It's chosen the correct tile in your screenshot, but it's a 50/50 chance that it will. Here's why.

image

There's the neighboring area of the tile, and underneath I have drawn it with just colors. Then to the right, there's the edge and the corner piece. Both of them match 7/8 neighbors, and are incorrect for 1/8 neighbors. It's different in both cases, but they score the same - not a perfect match, but close. Because they score the same, Better Terrain picks one at random based on their random weights (by default 50/50). That's why it is acting this way.

The second example is better, as it specifies less matching rules. That means there are less misses. However, the edges still only match against three water tiles, so in those narrow examples, they will cause at least 2 misses, where as the plain grass tile only causes 1 miss.

A more minimalist rule set might work better for you. Something like this:

image

The plain grass doesn't match against anything, it's just the default for grass. Edges occur when grass is adjacent to water. Corners occur when there is diagonal water, but it's got grass on both sides.

Even with those rules (rotated for all the tiles) there are still combos for which there are no good tile placements, but that might be suitable for your needs.

Wcubed commented 6 months ago

Thank you, that makes so much more sense now.

I see now I was thinking backwards about connecting tilesets. Because it doesn't have a tile for every single occurence, filling in every single connection rule forces it to pick between two that both don't entirely work. Even though one will work, but in over-constraining I told it "no this tile can't work here".

Telling it instead "use this tile, unless there is a tile that fits better", made it work :)