While putting together my own AI mostly from scratch, I’ve hit a bump in the patrol state I have setup. After reaching one waypoint, my AI won’t continue to the next one, despite being quite sure that my conditions to set the next point trigger and that I set the next one properly. I’ll copy the piece of code in question below:
public override void Update(enemyAI_FSM enemy)
{
// Check how close the enemy is to the player
if (enemy.distance <= enemy.lookRadius)
{
enemy.TransitionToState(enemy.ShootState);
}
// If the Waypoint Index is set to less than or equal to the total number of waypoints, start moving toward the currently selected waypoint
if (waypointIdx <= enemy.waypointList.Length && pointDistance > enemy.stopDistance)
{
enemy.transform.position = Vector3.MoveTowards(enemy.transform.position, currentPoint.transform.position, enemy.moveSpeed * Time.deltaTime);
}
// Then check if the waypoint has been reached, and select the next one
else if (pointDistance <= enemy.stopDistance)
{
Debug.Log("Waypoint reached");
if (waypointIdx < enemy.waypointList.Length)
{
waypointIdx++;
}
else if (waypointIdx >= enemy.waypointList.Length)
{
waypointIdx = 0;
}
currentPoint = enemy.waypointList[waypointIdx];
}
}
So, is there something obvious I’m missing? Thank you to anyone who can help