Idle Animation Problem

I have made a small animation test which consist of a Run, Attack and a Idle animation. I stole the script from the animation example project and rewrote it to suit my needs. But i have a problem with the Idle animation.
For some reason it does not go to the idle animation stance but just freezes in the middle of its run animation… the script im using is:

animation.wrapMode = WrapMode.Loop;

animation["Attack"].wrapMode = WrapMode.Clamp;

animation["Idle"].layer = -1;
animation["Run"].layer = -1;

animation.Stop();

function Update () {
	if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
		animation.CrossFade("Run");
	else
		animation.CrossFade("Idle");
		
	if (Input.GetButtonDown ("Fire1"))
		animation.CrossFadeQueued("Attack", 0.3, QueueMode.PlayNow);
}

Hope someone out there can help me… thx

1 Like

Check to make sure your animations are split correctly. You might have ‘idle’ animation named incorrectly or the frames that ‘idle’ plays is incorrect. Because I have the same exact thing you do (minus a couple of other things):

private var controller : CharacterController; 

function Start ()
{
	controller = GetComponent(CharacterController); 
	animation.wrapMode = WrapMode.Loop;
	
	animation["jump"].layer = 10;
	animation["jump"].wrapMode = WrapMode.ClampForever;
	
	animation["fall"].layer = 10;
	animation["fall"].wrapMode = WrapMode.ClampForever;
	
	animation["land"].layer = 10;
	animation["land"].wrapMode = WrapMode.Once;
	
	animation.Stop();
	animation.Play("idle");
}

function Update ()
{
	var MovementY = controller.velocity.y;
	var controller : CharacterController =  GetComponent(CharacterController);
	
	if ((MovementY > 0.1)  !(controller.collisionFlags  CollisionFlags.Below))
	{
	animation.CrossFade("jump");
	}
	else if ((MovementY < -5)  !(controller.collisionFlags  CollisionFlags.Below))
	{
	animation.CrossFade("fall");
	}
	
	if ( ((animation.IsPlaying("jump")) || (animation.IsPlaying("fall")))  (controller.collisionFlags  CollisionFlags.Below))
	animation.CrossFade("land");

	if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2)
	  animation.CrossFade("run");
	else
      animation.CrossFade("idle");		
}