- Home /
Question by
Artcom_Pro · Aug 06, 2014 at 03:46 PM ·
navmeshnavmeshagentpath
Find closest target on NavMesh for many possible targets
Hello, I'm trying to find the closest target, but no by absolute distance, but by distance of path on my NavMesh, my actual script is this :
//nma is NavMeshAgent;
Resource[] ress=FindObjectsOfType(typeof (Resource))as Resource[];
foreach(Resource res in ress)
{
nma.SetDestination(res.transform.position);
nma.Stop();
while(nma.pathPending)
{
yield return null;
}
float currentDistance=Tools.PathLength(nma.path);
if(currentDistance<currentNearestResourceDistance)
{
currentNearestResourceDistance=currentDistance;
nearestResourceTrans=res.transform;
resourceFound=true;
}
}
But my script calculates and checks a path for ALL targets before to pick the best target, how could i check around my source and stop when i found the first target on the navmesh tree?
Comment
Your answer
Follow this Question
Related Questions
Is it possible to store NavMeshAgents paths and assign them to other NavMeshAgents later? 1 Answer
Is it possible to assign a custom path to a NavMeshAgent? 0 Answers
Find the closest point of an Invalid or Partial path 0 Answers
NavMesh Update Path 0 Answers
Navmesh - How to calculate path AROUND NavmeshAgent Obstacle Radius? 2 Answers