Using this method to determine if my NavMeshAgent can reach it’s target destination doesn’t correctly work. If the target is unreachable by the agent, whether the target is simple not on the NavMesh or there is an obstacle blocking the path of the agent, CalculatePath always returns true.
Likewise, if I debug log out the NavMeshAgents path.status, if the target is not on the NavMesh at all, as in the GameObject itself is position far away from the test area, it still returns PathComplete.
Not sure what I’m doing wrong here.
using UnityEngine;
using System.Collections;
public class NavMeshController : MonoBehaviour {
public GameObject target;
NavMeshAgent agentController;
bool targetingPlayer = false;
Vector3 startPosition;
// Use this for initialization
void Start () {
agentController = GetComponent<NavMeshAgent>();
startPosition = gameObject.transform.position;
}
// Update is called once per frame
void Update () {
NavMeshPath path = new NavMeshPath();
Debug.Log(agentController.CalculatePath(target.transform.position, path))
if (agentController.path.status != NavMeshPathStatus.PathPartial)
{
agentController.destination = target.transform.position;
}
else
{
agentController.destination = startPosition;
}
}
}
Obviously it’s very basic and just for testing purposes, but I still don’t understand why It’s returning both Path Partial and Path complete when the navMesh agent clearly cannot reach the target destination. As well as why CalculatePath always returns true in the same scenario.