Wrong TargetReached with custom PathEndingCondition

Hello,

I have created a custom PathEndingCondition to find Nodes with special Tags.
It works great, but the reached target is always one node left from the found targetnode.

what am I doing wrong?

thx for help, and sorry for my bad english…

Log:
TargetFound
(5.0, -0.5, 2.0)
OnTargetReached
(4.0, -0.5, 2.0)

Code:

var gg = AstarPath.active.data.gridGraph;
GridNodeBase gn = gg.GetNode(1, 1);
gn = gg.GetNode(5, 2);
gn.Tag = 1;


var start = new Vector3(0, 0, 0);
var p = XPath.Construct(start, start);
p.endingCondition = new TagEndingCondition(1);
p.heuristic = Heuristic.None;
seeker.StartPath§;


Class:
public class TagEndingCondition : PathEndingCondition
{
public int tag;
public TagEndingCondition(int tag) {
this.tag = tag;
}
public override bool TargetFound(PathNode node) {
if (node.node.Tag == tag) {
Debug.Log(“TargetFound”);
Debug.Log((Vector3)node.node.position);
}
return node.node.Tag == tag;
}
}

Problem found, seeker start-/endpoint snapping “Node Connection” was the problem…
changed to “Node center” and everything works fine :slight_smile:

1 Like