Combining State Machine with Pathfinding

Hi, I have a wandering chicken, but I can’t seem to stop her randomly moving while in idle, and then also walking on the spot.

Can anyone see the issue with my code?

using UnityEngine;
using System.Collections;

public class ChickenAi : MonoBehaviour {

	public Transform[] wayPoints;

	NavMeshAgent navMesh;
	int randomNumber;
	public int behaviour;
	public Transform currentWaypoint;
	Animator anim;

	// Use this for initialization
	void Start () {
		
		navMesh=GetComponent<NavMeshAgent>();
		anim=GetComponent<Animator>();
		StartCoroutine(AnimalBehaviour());
	
	}

	IEnumerator AnimalBehaviour(){
		
			while (true) {
				
				//Choose a behaviour
				behaviour = Random.Range (0, 4);

			if (behaviour == 0) {

				//Choose a random waypoint
				randomNumber=Random.Range(0,wayPoints.Length);
				currentWaypoint=wayPoints[randomNumber];

				//go to selected waypoint
				navMesh.SetDestination (currentWaypoint.position);

				//Apply animation
				anim.SetTrigger("Walk");
		
			}
			else if (behaviour == 1) {
				
				anim.SetTrigger("Idle1");

				//stop Movement
				navMesh.ResetPath();

			} 
			else if (behaviour == 2) {
				
				anim.SetTrigger("Idle2");

				//stop Movement
				navMesh.ResetPath();
			} 
			else if (behaviour == 3) {

				anim.SetTrigger("Eat");

				Debug.Log ("Eating");
				//stop Movement
				navMesh.ResetPath();
			}
			yield return new WaitForSeconds(Random.Range(5.0f,6.0f));

		}
	}
}

I’ve tried using NavMesh.Stop() and navMesh.Resume() but still getting the mismatched behaviours.

Thanks

Code looks correct after a quick glance. I would make sure your animation’s don’t move the chicken. This has to deal with some animation settings and how it was animated.