A* How do I stop the enemy from jumping back when running to player

So I downloaded the arongranberg A* system and implemented it into my game. I used the basic script provided in the tutorial and modified it so it could run to the player and look at the player. I made it so it would always look at the player and so it would stop when it got at a certain distance from the player.
The problem I’m having is that the enemy keeps jumping back randomly. I tried applying a simple smooth but that didn’t help.

Here is a video of the problem I’m having: Unity Problem - YouTube

This is the current script I’m using:

public bool Static = true;
	
	//The object to move to
	public GameObject targetObject;
	
	private Seeker seeker;
	private CharacterController controller;
	
	//The calculated path
    public Path path;
	
	//The AI's speed per second
    public float speed = 10;
	
	//The max distance from the AI to a waypoint for it to continue to the next waypoint
    public float nextWaypointDistance = 3;
	
	//The distance from the player at which the AI stops
	public float DistanceFromPlayer = 3;
	
	
	//The waypoint we are currently moving towards
    private int currentWaypoint = 0;
	
	
	// Use this for initialization
	void Start () {
	    //Get a reference to the Seeker component we added earlier
        seeker = GetComponent<Seeker>();
        seeker.pathCallback += OnPathComplete;
		controller = GetComponent<CharacterController>();
		}
		
		animation["Run"].wrapMode = WrapMode.Loop;
	}
	
	private float TimeTillRecalc = 0.1f;
	// Update is called once per frame
	void Update () {
		if(!Static)
		{
			if(TimeTillRecalc <= 0)
			{
				seeker.StartPath(transform.position,targetObject.transform.position);
				TimeTillRecalc = 0.1f;
			}
			else
			{
				TimeTillRecalc -= Time.deltaTime;
			}
		}
	}
	
	public void OnPathComplete (Path p) {
        Debug.Log ("Yey, we got a path back. Did it have an error? "+p.error);
		if (!p.error)
		{
            path = p;
            //Reset the waypoint counter
            currentWaypoint = 0;
        }
    }
	
	 public void FixedUpdate () {
		
		
		
        if (path == null) {
            //We have no path to move after yet
            return;
        }
        
        if (currentWaypoint >= path.vectorPath.Count) {
            Debug.Log ("End Of Path Reached");
            return;
        }
        
		if( Vector3.Distance(transform.position,targetObject.transform.position) <= DistanceFromPlayer)
		{
			Debug.Log("Close enough to player");
			return;
		}
		
        //Direction to the next waypoint
        Vector3 dir = (path.vectorPath[currentWaypoint]-transform.position).normalized;
        dir *= speed * Time.fixedDeltaTime;
        controller.SimpleMove (dir);
		
			//Look at player
			transform.LookAt(targetObject.transform.position);
		
        //Check if we are close enough to the next waypoint
        //If we are, proceed to follow the next waypoint
        if (Vector3.Distance (transform.position,path.vectorPath[currentWaypoint]) < nextWaypointDistance) {
            currentWaypoint++;
            return;
        }
    }

The animation has root motion (it moves out of place, not in place). As the animation plays, the mesh is translated away from game object’s origin. When the animation loops back to the beginning, the mesh starts back at the origin again.

On top of that, your call to controller.SimpleMove() is translating the origin forward. If you turn off animation, you should see that your character slides forward at about half the speed of the video.

Two solutions are:

  1. Use a version of the animation without root motion. When you play the animation in the Animation window, the character should run in place.

  2. Or use Mecanim instead of legacy animation. Mecanim understands root motion. You won’t need to use controller.SimpleMove(). Instead, Mecanim will remove the mesh’s forward translation and apply it to the game object’s origin.