Animation stopped halfway through

I don’t know what I have done wrong. the animation went out smooth previously. It all happened after I added Rigidbody component to the GameObject.

Actually I am learning about animation and created one simple scene with a humanoid character and two cubes separated at some distance. the idea is when the character reached to a cube another animation runs and the character will move to the other cube.

the SetTrigger set off when the character reached the first cube. this takes place on the walk to attack transition. The attack animation then continues along with the walk animation when character start moving towards another cube.

this is my code

using UnityEngine;
using System.Collections;

public class animate_script : MonoBehaviour {
    public GameObject zombie, cube, otherCube;
    private GameObject zombie_instance;

    private Animator anim;
    int cubeFoundHash = Animator.StringToHash("TouchedUser");
    int attackAnimDone = Animator.StringToHash("AttackAnimDone");

	// Use this for initialization
	void Start () {
        //Vector3 zombie_pos = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, 650));
        //zombie_instance = Instantiate(zombie, zombie_pos, Quaternion.AngleAxis(180, new Vector3(0, 1, 0))) as GameObject;
        anim = zombie.GetComponent<Animator>();
        anim.SetBool(attackAnimDone, false);

        //cube = GameObject.Find("Cube");
	}
	
	// Update is called once per frame
	void Update () {
        
        StartCoroutine(WalktoCube(cube.transform));
    }

    IEnumerator WalktoCube(Transform target)
    {
        
        while (Vector3.Distance(zombie.transform.position, target.position) > 1.0f)
        {
            anim.Play("walk", 0);
            zombie.transform.position = Vector3.Lerp(zombie.transform.position, target.position,
                0.001f * Time.deltaTime);
            zombie.transform.rotation = Quaternion.Slerp(zombie.transform.rotation, target.rotation, 0.5f * Time.deltaTime);
            
            yield return 0;
        }

        if (Vector3.Distance(zombie.transform.position, target.position) < 1.0f)
        {
            anim.SetTrigger(cubeFoundHash);
            yield return new WaitForSeconds(0.5f);
            anim.SetBool(attackAnimDone, true);
            StartCoroutine(WalktoOtherCube(otherCube.transform));
        }
            
        //yield return new WaitForSeconds(0.5f);
    }

    IEnumerator WalktoOtherCube(Transform target)
    {
        while (Vector3.Distance(zombie.transform.position, target.position) > 1.0f)
        {
            anim.Play("walk", 0);
            zombie.transform.position = Vector3.Lerp(zombie.transform.position, target.position,
                0.001f * Time.deltaTime);
            zombie.transform.rotation = Quaternion.Slerp(zombie.transform.rotation, target.rotation, 0.5f * Time.deltaTime);

            yield return 0;
        }
    }
}

please help. i think this is simple task but it gives hard times for a newbie like me :slight_smile:

My bad…nailed it just now. I checked on the walk animation settings and found out that the Loop Time setting was unchecked.

Everything went ok but a very awkward thing happened when my character reached the other cube it sprung back to the first one. Did anybody find any mishap in my code?