Calculating Path Gives an Off Result

  • A* version: 5.3.8
  • Unity version: 6000.0.46f1

Im using Follower entity and recast graph.

Trying to calculate a path for display purposes, but the results are neither the shortest path nor the path that the FollowerEntity would follow if it were moving in that direction.

this is what im doing:

public void CalculatePath()
{
    Vector3 startPosition = _characterController.position;
    NNInfo startNN = AstarPath.active.GetNearest(startPosition);
    NNInfo endNN = AstarPath.active.GetNearest(this.targetPosition);
    ABPath path = ABPath.Construct(startNN.position, endNN.position, OnPathComplete);
    AstarPath.StartPath(path);
}

    private void OnPathComplete(Path p)
        {
            if (p.error)
            {
                Debug.LogError("PathFindingFailed");
                ClearDots();
                return;
            }
            List<Vector3> pathPoints = p.vectorPath;
            DrawDottedPath(pathPoints);
        }

You may want to look at GetRemainingPath(). Even if you need the path to be the full path, you can cache it after it’s created. If you’re constantly changing your path though this may not work as well.

Also, you can set that new ABPath as the new path for the FollowerEntity with SetPath().