C++ Get closest valid point in navigation mesh

Hi. As in title, I am looking some way or method to get closest navigable point for pathfinder to the point I pass. Here is what I tried:

Code: Select all

gEnv->pAISystem->GetNavigationSystem()->GetClosestPointInNavigationMesh(agentId, targetLocation, 100.f, 100.f, &correctedLocation);
And yes, it corrects location by a little bit, but it does not return exact position, when character gets in the end. I want absolutely accurate navigable point(closest to the specified), I am aware that not every point is navigable, and that navmesh is made of triangles.
For check IF point is navigable, I do

Code: Select all

bool bNavigable = gEnv->pAISystem->GetNavigationSystem()->IsLocationValidInNavigationMesh(agentId, targetLocation) && gEnv->pAISystem->GetNavigationSystem()->IsPointReachableFromPosition(agentId, m_pEntity, m_pEntity->GetWorldPos(), targetLocation);
So I combine these two methods to do the check, and it works pretty well.

Okay, figured out :D

This method - GetClosestPointInNavigationMesh - is correct. It works well. The reason why I didn't get always correct values was because I happened to pass positions, that are completely out of bounds of the navmesh to it, and therefore It wouldn't work.
Cryengine tutorial videos on my Youtube channel! Check it out !

Who is online

Users browsing this forum: No registered users and 2 guests