GetNearestForce not retrieving correct position

HI there,

I am having trouble in using GetNearestForce or GetNearest with or without constraints to find a precise position from one point to a point on the graph. I have had all sorts of combinations but this is the code I was using in general:

    public Vector3 GetNearestForcePosition(Vector3 position) {
        NNConstraint constraint = new() {
            walkable = true,
            distanceXZ = true,
            constrainWalkability = true
        };

        return (Vector3)graph.GetNearestForce(position, constraint).node.position;
    }

In the following screenshot one can see 5 units and the red spheres mark the aiPath.destination. For the two on the left I am using the upper method to find a position on the blue GridGraph because otherwise it would be on the same height as the others.
For some reason for the second left one it is working for the left most it is not. Generally, GetNearestForce is returning very inconsistent results. I tested with different graphs, with different node sizes and slope steepness.

Those are my Graph settings:

Hi

Since you have the GetNearestForce method, I suspect you are using an older version. Have you tried upgrading?

Thank you for the suggestion. I followed the upgrade process and also read the part about GetNearest() in the change log.

I have tried with all three choices for distanceMetric, of which only this one works slightly better:

        NNConstraint constraint = new() {
            walkable = true,
            distanceMetric = DistanceMetric.ClosestAsSeenFromAboveSoft(),
            constrainWalkability = true
        };

It behaves as expected in some more cases but still not in all, one .destination is still below of where it should be. :melting_face:

Never mind. Found the issue. Together with the new GetNearest() it works pretty well now.

Thanks again

1 Like