How to: Adjust Blocked Path Preferences (GridGraph)?

Hey there,

I currently have a problem with pathfinding that I can’t solve despite the very good documentation and hope you can help me.

My scenario is the following: I have a GridGraph where it can happen that no complete path can be generated between the start and destination, because the path is blocked by various unwalkable nodes. In this case, I currently generate paths whose end node has the shortest distance to the destination.

However, for my setting, I want the path to end adjacent to a certain type of unwalkable node (e.g. flagged by a specific tag).

In the attachment you can find a visualization of my problem.

How would you solve such a problem?

Thanks a lot in advance.

Hi

That’s a hard to define problem.
What would the expected result be in this case?
image

Hi Aron,
thank you for the fast reply.

The expected result in that case would be:

The idea is that the path should prefer ending adjacent to “none-walkable node 2” (e.g. a player building) over another none-walkable node, when the removal of “none-walkable node 2” would allow the target to be reached (think of a tower-defense game where the player can block the enemies path).

I hope this makes sense :smiley:

Hi

Sorry for the late answer.
It sounds like what you want is to calculate the path while assuming yellow nodes are actually traversable. But then you post-process the path to cut off anything after the first yellow node.

Hi Aron!

Thanks for the reply - your support is greatly appreciated :slight_smile:

What I want is that the path is calculated under the basic assumption that the yellow nodes are non-traversable (basic case - which works like a charm). However, if the path is not complete (does not reach the purple node), I want the path to be calculated as if only the yellow-nodes that prevent the path from being complete to be assumed to be traversable.

This is what Iam looking to achieve:

Do you have any idea how I can best achieve this within the Pathfinding Project?

You can solve the problem from the first post without using this library. I am a bad programmer, so I will write in human language.

In the top four green squares, assign a tag for example “not”. At the bottom of the yellow square, assign coordinates to Vector3. If the ray hits the “not” tag, then go to the coordinates of Vector3. When removing the yellow square, you need to remove the “not” tag.

@Denno

Yes. You can do that in the way I suggested.

You could for example create a modifier (see Writing Modifiers - A* Pathfinding Project) which removes all nodes (and points) from the path after it the first time it encounters a tag. Remove everything in the path.path and path.vectorPath lists after the first index where path.path[i].Tag == yellow.
You will also want to adjust your seeker settings to assign a very large penalty for traversing the yellow tag.

Thank you two for your responses :slight_smile:

I took your advice and got it working like you suggested with the path modifiers and the trimming of the path.path and path.vectorPath.

Thanks for the support and this really great tool!

1 Like