I have an enemy that randomly jumps between predefined waypoints. The enemy movement is made using the navmesh agent component.
Public Transform waypoints;
Public Tranaform waypoint;
Public int waypointIndex;
void Update() {
waypoint = waypoints[waypointIndex];
nma.SetDestination(waypoint.position)
}
void OnTriggerEnter (collider other) {
if (other.gameObject.tag == "waypoint")
{
waypointIndex = Random.Range(0,waypoints.length);
}
}
The problem is that sometimes the enemy randomly stops on certain waypoints. I have a feeling it has something to do with the fact that random range is calling the number that the waypoint is already on. Any ideas for making the random range number not calling the same number twice in a row. Or any other solution that I might be missing?
Ps. Sorry if the code is a little messed I’m writing it from memory on my phone.