Navmesh Agent isStopped not working, can't get navemesh agent to stop.
Hi, I'm having a total space cadet moment, but I can't seem to get my navmesh agent to stop at the end of a set of waypoints after 2 days and extensive googling/reading the forums, instead it circles around the last waypoint like it never met the distance threshhold, but I manually coded a distance threshold and the code runs for navMeshAgent.IsStopped = true; but the agent just continues to run forward and sparadic. If I adjust Agent values like speed/acceleration/stopping distance, eventually it'll circle around the waypoint, even though I've tried numerous ways to get it to drop the path and just stand still at the end of the waypoints.
void Update()
{
if (!gameManager.isHiked) //set by UI button to trigger into true
{
if (myRoute == null)
{
GetRoute();
}
return;
}
if (gameManager.isPass) //set by UI button, is true
{
if (isAtLastCut)
{
Debug.Log("last cut");
return;
}
RunRoute();
timeSinceArrivedAtRouteCut += Time.deltaTime;
}
}
private void RunRoute()
{
if (myRoute != null)
{
if (AtRouteCut())
{
if (IsEndofRoute())
{
navMeshAgent.isStopped = true;
isAtLastCut = true;
Debug.Log("Stop nav agent");
return;
}
timeSinceArrivedAtRouteCut = 0;
CycleRouteCut();
}
nextPosition = GetCurrentRouteCut();
}
if (timeSinceArrivedAtRouteCut > myRoute.routeCutDwellTime)
{
navMeshAgent.destination = nextPosition;
navMeshAgent.isStopped = false;
Debug.Log("start navemesh agent");
}
}
private void GetRoute()
{
myRoute = routes[0];
totalCuts = myRoute.transform.childCount - 1; //subtract 1 because arrays start at 0
Debug.Log("total cuts " + totalCuts);
Debug.Log(myRoute.transform.name);
}
private void CycleRouteCut()
{
if (IsEndofRoute()) return;
currentRouteIndex = myRoute.GetNextIndex(currentRouteIndex) //Route for i loop;
}
Answer by Skaster87 · Dec 08, 2019 at 01:39 AM
This was actually an animation issue, I thought I had root motion disabled on all animations in the project, but not the one during this sequence.
Your answer
Follow this Question
Related Questions
How to prevent AI from going Backwards 0 Answers
Enemy AI for Multiplayer (using NavMeshAgent) unity 5.6.5f1 0 Answers
Moving moving Object with left/right arrow keys in a circular direction 3 Answers
Object reference not set to an instance of an Object? 0 Answers
Why is my bool being set to true when program is run? 1 Answer