- Home /
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 :/
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");
}
Answer by Meltdown · Mar 22, 2012 at 06:05 PM
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");
}
}
It didn't seem to work :/
I'm using a character controller if that makes any difference to the code you wrote?
Also void FixedUpdate() isn't recognised
Thank you for your reply aswell :D
void is C#. If you using javascript change it to function. You need to add a rigidbody to your character controller. You also need to debug the speed so you can tell if it works.
Your answer
![](https://koobas.hobune.stream/wayback/20220613065419im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
HeadLookController 0 Answers
Character Animations 0 Answers
Fall animation when character is falling 3 Answers
Player Animation and control panel 2 Answers