Making an stealth game where enemy have a cone field of view, and have a set waypoint. Followed the unity doc for the waypoints for enemy, but i cant seems to figure out how to make the enemy stop for a few seconds at every waypoint. This code below is the one from Unity doc.
public Transform[] points;
private int destPoint = 0;
void Start()
{
//other line of codes....
agent.autoBraking = false;
GotoNextPoint();
}
void GotoNextPoint()
{
if (points.Length == 0)
return;
agent.destination = points[destPoint].position;
destPoint = (destPoint + 1) % points.Length;
}
void Update()
{
if (!agent.pathPending && agent.remainingDistance < 0.5f)
{
GotoNextPoint();
}
}
I have tried different mention, such as:
private waitTime;
public startWaitTime;
do a Time.deltatime, then put if(waitTime <=0)… it works that he stay at that waypoint for a few seconds, but hes not standing still, but circling around the waypoint then move on to the other.
i have also did agent.speed =0 when at waypoint, and agent.speed = 3 when the waitTime is <=0, but doing it this way, the ai will only follow the player when hes moving to the next waypoint.