Testing if there is a path without moving

Hi Everyone,

I am making a puzzle game where you you have to rotate objected until the connect Point A to Point B. So i have a question about using this Asset.

  1. How can i have the A* object repeatedly update the graph instead of just once? I would want it to be update like once a second or every 1/2 second, or maybe on “click” and tiles get moved and rotated. This would be to test if there is a path as the player moves tiles around.

Hi

You can recalculate the graph by calling the method

 AstarPath.active.Scan();

you can also make smaller, more localized graph updates. See https://arongranberg.com/astar/docs/graph-updates.php
If you have an object, you could attach the DynamicGridObstacle component to that obstacle, and then the the component will update the graph around that object whenever it moves or rotates (see the example scene called ‘Example2’ for an example).

You might also be interested in the PathUtilities.IsPathPossible method.

That dynamicgrid option is perfect for what i need.

Is there a way to test if there is a successful path without moving the object? So for instance if i wanted the object to remain stationary until a key pressed, but the key isn’t clickable until there is a successful path from point A to point B?

Hi

Yes. That’s doable with the PathUtilities.IsPathPossible method I mentioned in the last post.

Ah ok thanks.

Do you happen to have a tutorial or a guide on how to implement it? I looked at it in the documentation, but it’s a bit high level for my brain.

Hi

The documentation contains a code snippet that you can just plug into your code

Vector3 point1 = ...;
Vector3 point2 = ...;
GraphNode node1 = AstarPath.active.GetNearest(point1, NNConstraint.Default).node;
GraphNode node2 = AstarPath.active.GetNearest(point2, NNConstraint.Default).node;

if (PathUtilities.IsPathPossible(node1, node2)) {
    // Yay, there is a path between those two nodes
}