- Home /
Finding Closest Object Through Navmesh,Identifying Which Object Is Closest on NavMesh
I have a set of targets, and I want to find and move my NavAgent towards the closest one. My issue is that the distance in Vector3.Distance could potentially be much shorter than the distance it would actually take to get to the target. I want to do the check once for all objects, then set the NavAgent to find the target instead of doing the checks each Update Function.
I have successfully setup a loop that creates a path between the NavAgent and the target points. The issue is, since it is all in the same update function, the agent.remainingDistance check always returns 0. I have tried throwing a loop to delay the update, but the distance never updates from 0.
I don't want to wait the extra frame because the targets could be in opposite directions. Also, once it is committed to a target, even if another target gets closer I don't want it to update. So I want it to check all paths once, then stop checking.
Is there a way to calculate the path distance from the path in one update function?