Expansion Topic - Terrain Values

So you asked what we would love to see as an expansion on this, and what immediately comes to mind is how we didn’t change the terrain at all with the A* pathfinding. Presently it just tries to take the shortest path via obstacles, but not accounting for things like the terrain itself being hard to move over, like going from grass to mud or swamp or perhaps even an “elevated” position that would require more effort to get up.

What would potentially be involved in making things like this happen, as I greatly want to use A* for a sort of tower defense pathfinding that accounts for the ground terrain difficulty. Did we cover that and I’m blanking on it or is that something needing a few more tweaks?

1 Like

We didn’t cover ground terrain difficulty.
My approach to this is to put a component on the terrain tiles with a difficulty field. When setting up the pathfinding system, I check each location for a tile with a difficulty on it and add this as a field in the PathNode. I then multiply the GCost by the difficulty when setting it, which will give higher difficulty tiles a higher GCost (and by extension a higher FCost).

2 Likes

Yup, for the algorithm logic it’s as simple as adding an extra field in the PathNode and add that penalty when calculating the FCost

Then as to how you populate the A* Grid with that data you can do like @Brian_Trotter mentioned, make a simple object with a collider, then attach a script that contains the penalty data, when the Pathfining cycles through the entire world you check if that type of collider exists in that point, if so grab the penalty data and apply it to the underlying pathNode

2 Likes

Wouldn’t you also need to update the logic that displays walkable tiles to use pathfinding as well?

Not sure what you mean, the visual is already using Pathfinding to check if a position is walkable or not.
If you add a penalty code then the walkable distance will change and that change will be reflected in the visual.
Maybe you’re talking about a different visual if the underlying position has a penalty or not? Sure you could also add that logic on the visual.

This is similar to what I did here

In my case, I didn’t need ‘difficulty’ per se, just the holes

image

The ‘hole markers’ are just colliders on the ‘obstacle’ layer. In hindsight, I could’ve just made bigger colliders that covers a full area instead of a collider per tile

Yeah ignore my comment… I forgot the Move action was already taking the Pathfinding into consideration when evaluating whether a position was walkable or not.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms