How can I check the destination outside the navmesh?
I am a Unity newbie and designing an A.I. following the target position.
This target position is dynamically moving by the player's position trying to be like formation.
The problem is, I cannot check the A.I.'s destination is either reachable or not as I intended.
If the destination is outside the navmesh, it returns false, however, it returns true when the target position overlaps with any obstacle - where there is no navmesh.
here is my code to check if the destination is valid;
protected bool IsReachableDestination()
{
return _agent.enabled
&& _agent.CalculatePath(_currentDestination, _agent.path);
}
and screenshots;
In this case, the A.I. keeps trying to follow(walking) the target position (blue sphere) overlapped with an obstacle. The function returns true as well.
But there is no navmesh area as you can see.
When the target position is totally outside the navmesh, it just stays the closest where it could as I intended. Also, the function returns false.
In both cases, the destination is totally outside the navmesh area but returns a different result.
What am I doing wrong and how can I fix this?
Waiting for your help and advice!
Answer by mateuszwallace · May 22, 2021 at 05:56 AM
Try to use SamplePosition Method with small radius should be this what you want.
Your answer
Follow this Question
Related Questions
NavMeshSurface or NavMeshAgent agentTypeId can't be changed on runtime 0 Answers
Problem with NavMesh 0 Answers
=> How to Avoid NavMeshAgents Clumping Up Together?! <= 1 Answer
Navigatin Mesh agent works for ~10 seconds, then starts moving sporadically 0 Answers
Have players NavMeshAgent ignore Enemy NavMeshObstacle carving 0 Answers