Hi,
I have a very simple grid-graph project where some Character Controller AI using Seeker script and use a Transform for a target using AI Path. For some reason, which I cannot understand, they seem to favor one side of the Transform despite other edges being closer to them. This means that they all clump up on side of the Transform even when coming from multiple directions.
In the screenshot below, you can see the AI paths (green) of the little red AI capsules. The capsules, no matter if coming from upper-right or lower-left, all try to go to bottom center of the large yellow sphere. I’ve looked over the code in AI Path and Seeker and don’t understand why they would favor that side and not any other point equidistant from the center of the yellow sphere. Can anyone help? I’d like for the AI to target the closest side along their path.
Any ideas? Would it be somewhere in the Seeker script? I’m grasping at straws here…
I’ve created a work around using collider.bounds.GetClosestPoint(myPosition). I’m still very confused why it would result in such a behavior when creating the path in the first place though.
Hi
Sorry for the late answer.
The reason is that the pathfinding system will find a path from the closest node to the start point to the closest node to the end point. Even if you specify a point in the middle of that obstacle, some node will likely be closest, even if it is only by 0.00001 world units. It is not really up to my package to decide how much is an ‘acceptable’ distance. Even if it was actually exactly in the middle, only 4 nodes would be at the same closest distance (one above the obstacle, one to the right, one to the left and one below it) and all paths leading to those nodes would probably not be what you wanted anyway.
The easiest way to make something similar to what you want is to offset the target point slightly towards the unit position, which is exactly what you have done.
You can also use a MultiTargetPath with each node on the border of that obstacle which. I believe that would give you the exact behaviour that you want.
Another solution I am thinking about (but which I have not implemented yet) is some heuristic for determining if a node is close enough to the target compared to the estimated distance still left to the target).
1 Like