x


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"); 

}

more ▼

asked Mar 22 '12 at 05:53 PM

Joevis gravatar image

Joevis
1 9 13 13

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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");
    }
}
more ▼

answered Mar 22 '12 at 06:05 PM

Meltdown gravatar image

Meltdown
5.6k 18 25 49

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

Mar 22 '12 at 06:55 PM Joevis

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.

Mar 22 '12 at 07:06 PM Meltdown
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x5087
x3793
x524
x110
x41

asked: Mar 22 '12 at 05:53 PM

Seen: 769 times

Last Updated: Mar 22 '12 at 07:06 PM