Jump to content

NavMesh FindPath


Tim Shea
 Share

Recommended Posts

I can't seem to find any documentation for the NavMesh class, specifically the FindPath function. I need to check whether a path exists from an entity to a given point before invoking the GoToPoint method, and I was hoping I could use the FindPath method to do that.

 

I thought perhaps FindPath would return NULL if a valid path did not exist, but that doesn't seem to be the case.

 

Does anyone else know how to check if the path returned is valid, or is there some better way to do what I'm trying to do?

 

Thanks!

Link to comment
Share on other sites

Actually I just tested with a point that was completely outside of my level geometry (as opposed to just inaccessible) and FindPath did return NULL, so I stand corrected. However, my question still stands for obstacles, etc. If I set the destination inside a pillar for example, the entity will just endlessly try to walk into the pillar.

Link to comment
Share on other sites

You could check the distance between the final point in the path and the position you are setting. If the XZ distance is off by more than 0.1 or so that's a pretty good bet the target position is inaccessible.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Yep, that worked. I found that the precise destination point (plus the y bias of the character I think) is actually in the path, but not the last point. So, if I call find path with the point (5, 0, 5), the second to last point is (5, 1.25, 5), but the last point is (5.06##, 1.25, 5.039##). I'm not sure why this is. In any case, the skew on the final point is small enough that an epsilon of 0.1 ignores it.

 

This is my implementation (reduced to the general form), if anyone is interested:

 

bool PathExists(World* world, Entity* entity, Vec3 destination, float epsilon = 0.1)
{
 // Based on Josh's input and a quick test, this seems to work
 if (path != NULL)
 {
   Vec2 pathBackXZ = path->points.back().xz();
   Vec2 pointXZ = point.xz();
   return (pathBackXZ.DistanceToPoint(pointXZ) < epsilon);
 }
 else return false;
}

 

Thanks Josh.

  • Upvote 2
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...