- Home /
 
Nav Mesh Agents Not working
I have some nav mesh agents. They work fine...as long as only 2 or less are active. When all 3 zomibes(nav mesh agents) are active occasionaly there is flickering of the nav mesh(as if they are recalculating the path every frame). If there are 2 or 1 of them it works just fine. pop in the 3rd and it all breaks down. By the way it doesn't matter which 2, any combination works, it's a particular zombie thats causing the issue(they are all duplicates anyway). Here's the VIDEO (the flickering is less frequent in it because of video compression) And here's the zombie AI:
 #pragma strict
  
 var pPoint : GameObject[];
 private var findPlayer : GameObject[];
  
 var player : GameObject;
 var distToPlayer : float;
 var head : GameObject;
 var maxDist : float;
 var toIgnore : LayerMask;
  
 var agent : NavMeshAgent;
 var CurDest : Vector3;
 var distToDest : float;
 var minAngle : float = 120;
 var maxAngle : float = 240;
  
 var anim : Animator;
 var run : boolean = false;
  
 function Start ()
 {
         pPoint = GameObject.FindGameObjectsWithTag("PatrolPoint");
         findPlayer = GameObject.FindGameObjectsWithTag("Player");
         player = findPlayer[0];
         agent = GetComponent(NavMeshAgent);
         anim = GetComponent(Animator);
         NewDestination();
 }
  
 function Update ()
 {
         agent.SetDestination(CurDest);
         distToPlayer = Vector3.Distance(player.transform.position, transform.position);
         distToDest = Vector3.Distance(transform.position, CurDest);
         if(distToPlayer <= maxDist)
         {
                 head.transform.LookAt(player.transform);
                 Debug.Log(head.transform.localEulerAngles.y);
                 if(head.transform.localEulerAngles.y <= minAngle || head.transform.localEulerAngles.y >= maxAngle)
                 {
                         var hit : RaycastHit;
                         if(Physics.Raycast(head.transform.position, head.transform.forward, hit, 100, toIgnore))
                         {
                                 if(hit.transform.tag == "Player")
                                 {
                                         minAngle = 361;
                                        
                                         CurDest = player.transform.position;
                                         anim.SetTrigger("run");
                                         anim.SetBool("walk", false);
                                         agent.speed = 0.8;
                                 }
                         }
                 }
         }
         if(distToDest < 0.3)
         {
                 if(distToPlayer < 0.3)
                 {
                         CurDest = transform.position;
                         anim.SetTrigger("hit");
                 }
                 else
                 {
                         NewDestination();
                 }
         }
 }
  
 function NewDestination()
 {
         anim.SetBool("walk", true);
         agent.speed = 0.2;
         CurDest = pPoint[Random.Range(0, pPoint.Length - 1)].transform.position;
 }
 
              Your answer
 
             Follow this Question
Related Questions
Nav Mesh Agent 0 Answers
... Can only be called on an Active Agent that has been placed on a Nav Mesh? 2 Answers
Random Position on Nav Mesh 1 Answer
Generated mesh not showing up on my laptop 0 Answers
Why is the MeshFilter being removed? 1 Answer