When I assign new positions to the path, after it finishes calculating, it adds 30 more positions, and the points it adds are weird. Does someone know why?
The path the supposed to be
the actual path after calculation
The Code
[SerializeField] Vector3[] points;
public event Action FinishedCaculatePath;
[SerializeField] Seeker seeker;
public void CalculatePath(Vector3[] points)
{
// Create a new path instance
Path path = ABPath.Construct(transform.position, points[points.Length - 1], finishedCaculatePath);
// Add intermediate target positions to the path
NNConstraint constraint = NNConstraint.Default;
for (int i = 0; i < points.Length - 1; i++)
{
GraphNode node = AstarPath.active.GetNearest(points[i], constraint).node;
var position = (Vector3)node.position;
path.vectorPath.Add(position);
}
// Call the A* Pathfinding API to calculate the path
seeker.StartPath(path);
//AstarPath.StartPath(path);
}
private void finishedCaculatePath(Path path)
{
FinishedCaculatePath?.Invoke(path);
}
The Code