Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Joevis · Mar 22, 2012 at 05:53 PM · animationcontrollerjumpingfall

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

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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");
     }
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Joevis · Mar 22, 2012 at 06:55 PM 0
Share

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

avatar image Meltdown · Mar 22, 2012 at 07:06 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges