Hi, I am building a turn-based combat system, and so far, it works as intended until there is no possible path between objects. I guess what happens is A* is trying to find the most “okay” path possible, which I do not want. For example, in the picture, A* calculates a path from green to red with 2 counts.
And here finds a path from red to green with 7 counts.
So how can I detect when there is no path?
Here is my path find method in case it is needed.
int UpdatePath(GameObject pathTarget)
{
Path p = GetComponent<Seeker>().StartPath(transform.position, pathTarget.transform.position, OnPathComplete);
AstarPath.BlockUntilCalculated(p);
Debug.Log("Path Found! Path Count is " + path.vectorPath.Count);
path = p;
int count = path.vectorPath.Count;
return count;
}
void OnPathComplete(Path p)
{
if (!p.error)
{
currentWaypoint = 0;
path = p;
}
else Debug.Log("error");
}
Thanks in advance for the help.