Get the cost between 2 points

Hello ,
I have mulitple waypoints in my level, i need to find which one i can get to with the lowest cost, is there any function that return the cost or the distance between 2 points ?
Cheers

Hi

If you want to find the path to the closest of a number of target points, then you might be interested in the seeker.StartMultiTargetPath method.
See https://arongranberg.com/astar/docs/class_seeker.php#a811996024eca2a032ad58c847ee2871f

Otherwise you can define a method like this

public float Distance (Vector3 a, Vector3 b) {
     ABPath path = seeker.StartPath(a, b, null);
     path.BlockUntilCalculated();
     // Calculate the length of the path. This is only the same as the cost if you are not using penalties in your graph.
     // If you are not using penalties this will work well
     return path.error ? float.PositiveInfinity : path.GetTotalLength();
}

Hi Aron Thanks for your reply, i’ll try the StartMultiTargetPath method, but i tried before to use path.BlockUntilCalculated(); but i couldn’t find it in the ABPath or Path class, is it a new function added in a newer version ? my current version is 3.8.6 .
Thanks again

Hi

Ok.
Yes, but it exists in 3.8.6 using a different name. I renamed it in 4.x to make the behavior of it more obvious.
You can use

AstarPath.WaitForPath(path);

which is equivalent to

path.BlockUntilCalculated();

okay Thanks again :slight_smile: