Path Constraints Tutorial
This tutorial continues from the Getting Started tutorial. It is recommended you complete that one before starting this.
The final result can be found in the sample scene GrassPathsWithPathConstraint.
Note
Path constraints are only available in Tessera Pro
So far we succeeded in generating a level composed of grass and path tiles:
However, for many purposes, a level like the above is not acceptable. If the player is only able to walk along the path, then it's not possible for the player to walk over all the path tiles of the map, there is simply no route between them.
So far, all our generation has been local - that is, we've controlled what tiles are placed next to each other, without any regard for the overall structure. Now we are going to use the PathConstraint to assert some global behaviour on the map. The path constraint can be used in various ways, this is only an introduction.
Setup
First select the generator object. Enable the backtrack
option. Backtracking makes the generator try harder to find a viable solution. It's necessary when using the path constraint as the generator can otherwise get stuck trying to find a valid path.
Next, add a Path Constraint
component to the generator. We need to configure the constraint, by telling it what we consider a path.
Recall that we colored the tile edge green if that edge was grassy, and brown if that edge had a path. We can give that information to the constraint.
Check the "Has Path Colors" checkbox, and then check the color corresponding to the path.
This tells the generator to search for all the sides of tiles that have that color painted in the center of the face. If two such sides connect together, then it considers there is a path between those two tiles. The constaint then ensures that all path tiles connect to each other.
If we run the generator now, it'll only ever generate a single path:
Getting fancier
Let's add the tile_split
tile to the generator, as you can get a lot more interesting paths once you allow junctions. The constraint will still ensure that it's always possible to walk accross the map.
Add a tile_endRound
to opposite corners of the generated area as a pinned tile. Pinned tiles are ignored by constraints (unless using PinType.Pin), but the brown painting on these tiles forces adjacent tiles to be paths, and thus the path constraint must connect them together.
A few last tweaks: Set the skybox to the tile
object to stop the path going off the edge of the map. And set the weight of the tile
object to 10, increasing the ratio of grass tiles to path tiles.
Now we have a generator that makes self-contained full navigable maps. Here's a few results.
Additional options
The Path constraint default to ensuring all tiles are connected, but has several other options too.
Connected
When connected is true, then the constraint forces that all path tiles must have a contiguous path between them.
Connected is on by default.
Loops
Setting loop forces there to be at least two non-overlapping valid paths between any two connected path tiles.
Acyclic
Setting acyclic to true bans all cycles, forcing a tree or forest.
Prioritise
Prioritise is an experimental features. When true, Tessera prefers picking cells near the path for generation over other tiles. This can improve search quality.
Parity
Experimental setting. Enable this if your path tileset includes no forks or junctions, it can improve the search quality.