Portponky / better-terrain

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

[question] Help with understanding matching rules #85

Closed emanresU102396 closed 7 hours ago

emanresU102396 commented 2 months ago

I've had some troubles that I've run into while trying to use terrains, and I don't understand the matching system well enough to know whether the features I want exist or not (or if they even would work in the first place). I think my main point of confusion is in regards to the 'strictness' of matching rules. Sometimes, I want a tile to be considered a match if, say, the left and right neighbor match, without taking into account other neighbors (unless another tile is an even more exact fit). Sometimes, I want a tile to match if there's another tile of the same terrain to the left OR the right; or maybe I want it to match if there's a tile above, AND a tile to the left or right. Maybe I want to match if there's neighbors on the left and right, and NOT any neighbor above; or I want to match if there's a tile of terrain A above AND a tile of terrain B to the right; or if there's a tile of terrain A above OR a tile of terrain B to the right; or so forth... In short, I want to have control over how strictly a tile matches its neighbors. My questions are:

  1. How does matching work by default? How is a tile's "score" calculated? If one matching rule specifies terrain A above, and one has nothing marked above, what happens when terrain B is above the tile? If I connect a tile to multiple terrains or categories, does it count as a match when any of them match, or when all of them do? And so on.
  2. Is there a way to control matching rules the way I want to? For instance, some way to say "this tile matches EITHER of these two patterns", or "this tile should only be used if its neighbors EXACTLY match this pattern". If so, how? And if not, is this a feature that could feasibly be implemented?

Apologies if these questions are unclear/unnecessary/unreasonable/uninformed/etc, or if any of this info is in the tutorial video. (I did watch said video, but it was a while ago, and I may have overlooked or forgotten this information. But I'm not about to hunt through a 30-minute video in the hopes that the information I want might be somewhere in it.)

Thanks in advance for any help/answers you can provide.

Portponky commented 2 months ago

Tiles are scored based on their peering types. For each direction, if there are peering types set, the tile gets a score bonus if any of those types match (+3). If they do not match, it gets a big penalty (-10). If there are no peering types for that direction, it does not affect the score. The highest scoring tile of the correct type is placed. In the case of a tie, it picks a (weighted) random tile from the best.

As for your specific questions:

  1. If a tile matches terrain A above, but is placed with terrain B above, it will score badly for the upwards direction. It may still be placed if no other tile scores better. If a tile has multiple terrain peering types, it scores when matching against any of them.
  2. If you want two different matching rules on one tile, you can use alternate tiles to create duplicates of tiles and give them different rules. Check the godot docs about alternate tiles. There is no way to force a tile to be used only when it matches exactly - this could leave the tiling algorithm in a situation where it has no tile to place, but must place something.

Hope this helps. No need to apologise, questions are always welcome.