Animation don't play again

Hey guys
I got a Problem with playing my walk animation.
I programmed an AI which follow me if I’m 10 meters away from it.
And it stops walking when it’s nearlyer than 10 meters to me.
And here is my problem :
My AI play the Animation Walk(In script called Take)When I’m 10 meters away.If im nearlyer than 10 meters it stops playing the walk animation and that’s right but now when I’m again 10 meters away it don’t start the walk animation again
please help me
here’s my code

	protected void Walk (Vector3 targetPosition){ //***
	
		Vector3 velocity;
		Vector3 moveDirection = transform.TransformDirection(Vector3.forward);
		
		Vector3 delta = targetPosition - transform.position;
		
		
		if(delta.magnitude > minimalDistance)
		{
		velocity = moveDirection.normalized * movingSpeed * Time.deltaTime;
			characterAnimationState = AnimateState.Take;//**::

		}
		else{
			
			velocity = Vector3.zero;
			animation.Stop ();
				
		}
		
		rigidbody.velocity = velocity;
	}

You didn’t tell the object to start the animation again. You should try the following:

protected void Walk (Vector3 targetPosition){ //***
 
       Vector3 velocity;
       Vector3 moveDirection = transform.TransformDirection(Vector3.forward);
 
       Vector3 delta = targetPosition - transform.position;
 
 
       if(delta.magnitude > minimalDistance)
       {
       animation.Play();
       velocity = moveDirection.normalized * movingSpeed * Time.deltaTime;
         characterAnimationState = AnimateState.Take;//**::
 
       }
       else{
 
         velocity = Vector3.zero;
         animation.Stop ();
 
       }
 
       rigidbody.velocity = velocity;
    }

Note the change I made to the first if-statement. I put animation.Play() in there. so now, if it gets into range again, it’ll start walking again. Now, as I am not entirely sure of the syntax of animation, I am pretty sure it’s animation.Play(). Good luck

-Hybris

Thanks it’s working now :slight_smile: