#NavMeshAgent Gets stuck on Waypoint 1 and Doesn't Move to WP 2....

1 messages · Page 1 of 1 (latest)

lunar halo
#

Video Has Info of the Problem
CODE:```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

public class EnemyAI : MonoBehaviour
{
[SerializeField] private NavMeshAgent navMA;
[SerializeField] private GameObject player;

[SerializeField] private Transform[] desPoints;
private int desPointIndex;
private Vector3 target;
//[SerializeField] private GameObject p1;
//[SerializeField] private GameObject p2;

[SerializeField] private float seekDista;
private bool isChaching;
[SerializeField] private LayerMask playerMask;

RaycastHit hit;

void Start()
{
UpdateDestination();
}
void Update()
{
if(Vector3.Distance(transform.position, target) < 1){
IterateWayPointIndex();
UpdateDestination();
}
else if(Physics.Raycast(transform.position, transform.forward, out hit, seekDista, playerMask)){
ChacePlayer();
}
}

void UpdateDestination()
{
    target = desPoints[desPointIndex].position;
    navMA.SetDestination(target);   

}

void IterateWayPointIndex(){
    desPointIndex++;
    if(desPointIndex == desPoints.Length){
        desPointIndex = 0;
    }

}

void ChacePlayer(){
    navMA.SetDestination(desPoints[4].position); 
    StartCoroutine(ChaceGiveUpTime());
    if(!Physics.Raycast(transform.position, transform.forward, out hit, seekDista, playerMask) && isChaching == false){
        desPointIndex = 0;
        return;
    }
}

IEnumerator ChaceGiveUpTime(){
    isChaching = true;
    yield return new WaitForSeconds(5);
    isChaching = false;
}

}```

#

Okay the video was mkv

#

Moment...

#

Here

#

But Now i will Go sleep.

#

So don't wonder if i don't respond

lunar halo
#

SOLVED!

#

I changed this line from if(Vector3.Distance(transform.position, target) < 1) to
if(Vector3.Distance(transform.position, target) < 1.5f)in Update.