Tim Shea Posted November 29, 2013 Share Posted November 29, 2013 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! Quote Link to comment Share on other sites More sharing options...
Tim Shea Posted November 29, 2013 Author Share Posted November 29, 2013 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. Quote Link to comment Share on other sites More sharing options...
Rick Posted November 29, 2013 Share Posted November 29, 2013 I agree that being able to check the path before using has benefit. In my game I would also like to know about the path to do some cost stuff for movement. 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted November 29, 2013 Share Posted November 29, 2013 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. Quote 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 More sharing options...
Tim Shea Posted November 29, 2013 Author Share Posted November 29, 2013 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. 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.