Answer the question
In order to leave comments, you need to log in
Why do objects sometimes get stuck in navmesh?
I made 2 points A and B at the bottom of the map and at the top, before starting I check the path
public bool GetAccessPath(Vector3 TargetA, Vector3 TargetB){
bool ret = false;
MeshAgentPath = new NavMeshPath();
NavMesh.CalculatePath(TargetA, TargetB, NavMesh.AllAreas, MeshAgentPath);
if(MeshAgentPath.status == NavMeshPathStatus.PathComplete){
TargetCell = TargetB;
MeshAgent = GetComponent<NavMeshAgent>();
MeshAgent.updateRotation = false;
MeshAgent.updateUpAxis = false;
MeshAgent.Warp(TargetA);
MeshAgent.SetDestination(TargetCell);
ret = true;
}
return ret;
}
++Num;
Obj[Num] = Instantiate(cell) as Cell;
Obj[Num].transform.SetParent(Cells.transform);
Obj[Num].GetComponent<NavMeshAgent>().speed = Speed;
if(!Obj[Num].GetAccessPath(TargetA, TargetB)){ Obj[Num].gameObject.SetActive(false); }
if(Vector3.Distance(transform.position, TargetCell) > 0.5f){ .....
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question