Hey Ben, :)
Thank you for the reply! Currently, I only have a few hundred NPCs but I'm planning on handling ten thousand or so by the time the game is done.
I read what you said about following the string-pulled path and that it should be always over detail polys but could be on the border and cause an issue.
I decided to keep speed in mind even though it's very early on and avoid querying all polygons in the tile. So this is what I did.
Call findPath
Call findStraightPath
Simulate a crawl between each of the points returned by findStraightPath. In doing this:
(1) I call closestPointOnPolyBoundary on each interpolated position,
(2) I simultaneously follow along with a pointer to the poly array returned by findPath, checking to see if closestPointOnPolyBoundary works, if it fails, I move on to the next poly
What's happening is my interpolated path from point to point is ends up failing and not resyncing with the next poly from findPath so it crashes and burns. I speculate that the reason is because of the numerical imprecision you speak of. But, then again, it should be very rare. And this has happened on 3 out of 5 paths I've tried. Therefore, I think something else must be wrong. By the way, I've tried using closestPointOnPoly() in place of closestPointOnPolyBoundary() but it also failed on the same three paths.
When I say I interpolate from corner to corner, I'm doing this (as an example):
x1/y1/z1 = 1st corner
x2/y2/z2 = 2nd corner
deltaX=(x2-x1)/50; deltaY=(y2-y1)/50; deltaZ=(z2-z1)/50;
for(int i=0;i<50;i++) {
<check the location x1,y1,z1>
x1+=deltaX; y1+=deltaY; z1+=deltaZ;
}
When I check a location and it fails, I assume the location must be over the *next* polygon so I increment my poly pointer. Unfortunately, this doesn't work. It'll get through the rest of the polygons (from findPath) without a hit.
Any ideas? :(