# Find two paths (left and right shifted one unit), and take the faster one

I want to do the following :

Player chooses a point,

I make a new point that == point + shift, and another new point == point - shift.

I then want to calculate paths for the point + shift position, and the point - shift position, and send the fastest to my guy.

How do I do that?

I should clarify why I want to do this.

I’m telling the Seeker to move to a place which is unmovable. I want it to take the shortest path to reach the edge of that object. Instead, it seems like it shifts to the closest node, and calculates a path there. This means that sometimes it just randomly picks the opposite side of the obstacle and goes here instead of actually going towards to the obstacle.

My current code looks something like :

public void fct1(Gameobject attack)
{
Vector3 pos = this.transform.position;
Vector3 try1 = attack.transform.position + shift;
Vector3 try2 = attack.transform.position - shift;
Pathfinding.Path path1 = Pathfinding.ABPath.Construct(pos, try1);
Pathfinding.Path path2 = Pathfinding.ABPath.Construct(pos, try2);
StartCoroutine(assign_fastest_path(path1, path2));
}

IEnumerator assign_fastest_path(Pathfinding.Path path1, Pathfinding.Path path2)
{
while (! (path1.IsDone() && path2.IsDone()))
{
Debug.Log(“Still waiting for path1 and path2 to be completed”);
yield return null;
}
Debug.Log(“Found paths 1 and 2”);
if (path1.GetTotalLength() <= path2.GetTotalLength())
{
this.gameObject.GetComponent<Pathfinding.Seeker>().StartPath(path1);
}
else { this.gameObject.GetComponent<Pathfinding.Seeker>().StartPath(path2); }
}
*

but for some reason it never leaves the “waiting for them both to be done” state… like it gets caught in the while loop forever.

Hi

In your code you never actually calculate the paths. `ABPath.Construct` will only create the path object, it will not calculate the path. For that you will need `AstarPath.StartPath(path)`. See https://arongranberg.com/astar/docs/callingpathfinding.html

You might also be interested in https://arongranberg.com/astar/docs/multitargetpath.html