Specifying nodes to be only walkable to in ConstantPath

Hi there, first of, great resource you put together, bought the pro version yesterday to support you and to get access to ConstantPath.

I am writing a turn based strategy game where I use ConstantPath to search for movement possibilities of a unit based on its speed (speed is the number of nodes it could traverse in a single turn). I haven’t quite figured out if it is possible to specify the number of nodes (including diagonal movement) when generating a graph so that specifying e.g. 3 would result in a square area to be walkable as opposed to the G score which results in a more circle like result area. Any pointers in the right direction if this is doable are appreciated.

However the more pressing question I have is if it is possible to specify certain nodes to be only walkable to (i.e. when pathfinding reaches it during path calculation that it would consider it the end node of said path). What I am looking for is when my unit wants to calculate its possible movement it needs to stop once it is adjacent to an enemy unit. And if its speed is 5 and the enemy unit is located 3 nodes away it should only allow movement up to but not including the enemy unit but should allow movement up to its speed in any direction from any nodes that do not have a connection to an enemy unit.

I was thinking that specifying a node to be only walkable to from other neighbouring nodes would accomplish this, however I am at a loss as to how to get started with this or if it is at all possible.

Any help is appreciated,
Ben

Hi

The easiest method is to modify the grid graph slightly.
If you open up GridGenerator.cs you can find a method where it defines the costs for moving in all directions. For diagonal directions it specifies that as sqrt(2)straightCost, change that to just “straightCost”, so diagonal and straight movements cost the same, this will in effect make the constant path calculate exactly what you want.
You can change straightCost to 1 exactly for even better results, but then you will need to disable the Heuristic (A
Inspector -> Settings) if you are going to use normal pathfinding as well, otherwise it will generate suboptimal paths.

For the second one, I can’t really give you a quick solution. But a good thing about the constant path is that it returns the nodes ordered by distance, so you could loop through them and check for the first node which is adjacent to a node which an enemy is standing on.

The constant path will only search walkable nodes, never unwalkable ones.