Hello I just watched the live training by Matthew-Schell on Using Interfaces to Make a State Machine for AI
Great stuff. i was able to duplicate his results with my game (in progress). but i ran into a strange behavior when I tried to duplicate my enemy guy. I set up one enemy as per the training session and he works wonderfully. So I turned him into a prefab and then duplicated him with another start location. The two enemies start of wonderfully but when they cross each other’s paths they just stop… Not sure why.
I know nothing of that video but I’m sure it’s good stuff. But the important thing you need to develop is some debugging skills. So let’s get you started on some debugging.
Do you know what state the enemies are in before they cross paths?
What state do they transition to when they cross each other’s paths (if it even changes).
Is there any detection/collider logic happening that influences choices?
Is the nav mesh stopping when a collision is happening?
Your enemies don’t have a “Player” tag on them right? (They shouldn’t)
You should do some print statements to find out what is exactly happening or pause the game at certain points to analyze your gameobject conditions.
I’m guessing your code isn’t off from what the video has. A potential theory of mine that seems likely has to deal with this part of the code in the PatrolState.
void Patrol ()
{
enemy.meshRendererFlag.material.color = Color.green;
enemy.navMeshAgent.destination = enemy.wayPoints [nextWayPoint].position;
enemy.navMeshAgent.Resume ();
// This part is likely why your enemies stop
if (enemy.navMeshAgent.remainingDistance <= enemy.navMeshAgent.stoppingDistance && !enemy.navMeshAgent.pathPending) {
nextWayPoint =(nextWayPoint + 1) % enemy.wayPoints.Length;
}
}
Inside that if statement, put a Debug.Log or some other print statement and see when the enemies paths cross (and they stop) if the print statement is still printing. My guess is that it isn’t printing anymore. This would be the cause of the enemies to not go to their next waypoint position.