Character fall animation

Hi

I am trying to activate a fall animation when the character controller is falling to the ground.

I can’t seem to get it working :confused:

I was wondering if there was a solution to the problem!

Here is the animation code I have written so far

function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);

animation["jump"].layer = 1;
animation["fall"].layer = 1;

//Horizontal & Vertical Animations

if (Input.GetAxis("Vertical") > 0.1)

   	animation.CrossFade("jogForwards");
  
else if (Input.GetAxis("Vertical") < -0.1)

	animation.CrossFade("jogBackwards");
	
else if (Input.GetAxis("Horizontal") > 0.1)

	animation.CrossFade("jogRight");
	
else if (Input.GetAxis("Horizontal") < -0.1)

	animation.CrossFade("jogLeft"); 	
	    	   	    	    	   	    	    				   	    	    	
else

	animation.CrossFade("idle");
	
if (Input.GetButton("Jump"))
	
	animation.Play("jump"); 

}

You can check the y component of the velocity vector and if it is less than 0 (i.e your character is falling down) play the animation.

void FixedUpdate()
{
    if(rigidbody.velocity.y < 0f)
    {
      animation.CrossFade("fall");
    }
}