- Home /
This question was
closed Sep 12, 2018 at 09:13 PM by
Sam-Robichaud for the following reason:
Problem is not reproducible or outdated
Question by
Sam-Robichaud · Sep 11, 2018 at 12:23 PM ·
aicharactercontrollerpathfindingagentpatrol
AI Patrol getting stuck on first waypoint
I'm trying to modify the AIThirdPersonController to patrol along a set of waypoints.
For some reason he just seems to get stuck on the first waypoint.
I'm fairly certain when it gets to the first waypoint it switches through all the way points too fast and gets stuck moving in place, but I can't figure out how to slow it down, or only check once.
Any help appreciated.
using System;
using UnityEngine;
namespace UnityStandardAssets.Characters.ThirdPerson
{
[RequireComponent(typeof (UnityEngine.AI.NavMeshAgent))]
[RequireComponent(typeof (ThirdPersonCharacter))]
public class AICharacterControl : MonoBehaviour
{
public UnityEngine.AI.NavMeshAgent agent { get; private set; }
public ThirdPersonCharacter character { get; private set; }
public Transform[] points;
private int destPoint = 0;
private void Start()
{
agent = GetComponentInChildren<UnityEngine.AI.NavMeshAgent>();
character = GetComponent<ThirdPersonCharacter>();
agent.updateRotation = false;
agent.updatePosition = true;
agent.autoBraking = false;
GotoNextPoint();
}
void GotoNextPoint()
{
// Returns if no points have been set up
if (points.Length == 0)
return;
// Set the agent to go to the currently selected destination.
agent.destination = points[destPoint].position;
// Choose the next point in the array as the destination,
// cycling to the start if necessary.
destPoint = (destPoint + 1) % points.Length;
}
void Update()
{
if (agent.remainingDistance > agent.stoppingDistance)
{
character.Move(agent.desiredVelocity, false, false);
}
else if (!agent.pathPending && agent.remainingDistance < 0.5f)
{
GotoNextPoint();
}
}
}
}
Comment
Answer by Sam-Robichaud · Sep 12, 2018 at 09:13 PM
Well it just started working today... I don't know why... so I guess this is resolved.