I’m trying to get my agent to path to a cube (that represents a resource point). The Cube itself has a navmesh cutter so cuts out a small piece out of the navmesh to keep agents trying to path trough it until the resource disappears. The agent uses the Closest On Node Surface endpoint snap option in the seeker component.
However when I set the resource cube as a destination, the actual path destination is not put on the closest edge of the navmesh (as I would have expected) but on the opposite side of the cube for some reason.
Am I missing something here? Perhaps I set up something incorrectly?
(Using A*Pro 4.2.17)
I am having nearly the exact same issue - see my post here: Floodpaths are not taking the direct route .
For me it happened when I started using flood-paths. Are you using flood paths?
I think the funnel modifier is supposed to fix the paths so they don’t do that. If you haven’t tried it already, give that a shot. I’m starting to wonder if maybe the funnel modifier doesn’t work on tracer paths.
Apparently it happens with ABPaths as well as FloodPaths. Also, I was wrong in my previous post - the funnel modifier helps but it does not fix it. You and I are having the same problem - my post is here: https://forum.arongranberg.com/t/paths-dont-take-the-direct-route. I have narrowed it down to being an issue with the navmesh cutter, but we will have to wait for help from someone else to figure out how to fix it.
The underlaying issue here is that you request a path to a specific point. If this point is not on the navmesh, the pathfinding system will find the closest point on the navmesh and calculate the path to that point. In this case it turns out the closest point on the navmesh was on the right side of that cut (maybe only closer by 0.0001 meters, but still closer), and so it will calculate the path there. The ‘ClosestOnNodeSurface’ means ‘calculate a path to a point on the navmesh surface which is closest to my given destination’.
A common trick you can make if you want to move to the center of an object like this is to bias the destination point slightly towards the agent’s current position. I.e. do something like:
destination = cubeCenter + (agent.position - cubeCenter).normalized * 0.1;
This will put the closest point on the navmesh on the same side of the cube as the agent is right now, which is likely to be better.
Aah ok, I misinterpreted the ClosestOnNode modifier then. I assumed it would snap to the closest node while still having the shortest path. But as I understand now (and reading the docs again) it is more of a post process after the initial path has been calculated.
Thanks for the insight. The offset trick works like a charm!