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 CyberArtist · Aug 11, 2014 at 09:19 PM · animationgetkey

Jump/FallDown animation plays only once

When I press the Jump key, the Jump animation clip plays, (and for some reason) the FallDown clip immediately after. However, when I press the Jump key again, nothing plays. What's causing this? Also, how do I make the FallDown clip play only when my character touches the ground after the Jump?

Here are my scripts (with some lines from the beginning/end of the script not necessary to show):

Controller:

 //Move the controller during the fixed frame updates
 function FixedUpdate()
 {
     if(!isControllable)
         Input.ResetInputAxes();
     else
     {
         if(grounded) 
         {
             //Since we're touching something solid, such as the ground, allow movement
             //Calculate movement directly from input axes
             moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
             moveDirection = transform.TransformDirection(moveDirection);
             moveDirection *= walkSpeed;
             moveDirection.y -= gravity * Time.deltaTime;
             
             //Find rotation based upon axes if need to turn
             moveHorz = Input.GetAxis("Horizontal");
             if (moveHorz > 0)    //Right turn
                 rotateDirection = new Vector3(0, 1, 0);
             else if (moveHorz < 0)    //Left turn
                 rotateDirection = new Vector3(0, -1, 0);
             else    //not turning
                 rotateDirection = new Vector3(0, 0, 0);
             
             //Jump controls    
             if(Input.GetButton("Jump"))
             {
                 if(Input.GetButton("Run") && Input.GetButton("Jump"))
                 {
                     moveDirection.y = jumpSpeed/3;
                 }
                 else
                 {
                     moveDirection.y = jumpSpeed;
                 }
             }
             //Aplly any boosted speed
             if(Input.GetButton("Run") && Input.GetAxis("Vertical"))
             {
                 if(MoaliaStatus.stamina > 0)
                 {
                     isRunning = true;
                     if(MoaliaStatus)
                     {
                         moveDirection *= runSpeed;
                         MoaliaStatus.stamina -= MoaliaStatus.runUsage * Time.deltaTime;
                         isRunning = true;
                     }
                 }
                 else if(MoaliaStatus.stamina <= 0)
                 {
                     isRunning = false;
                 }
             }
             
             if(MoaliaStatus)
             {
                 if(MoaliaStatus.stamina <= MoaliaStatus.maxStamina)
                 {
                     MoaliaStatus.stamina += MoaliaStatus.staminaRecharge * Time.deltaTime;
                 }
             }
         }
     
         //Crouch the controller
         if(Input.GetButton("Crouch"))
         {
             controller.height = crouchHeight;
             controller.center.y = controller.height/2;
             moveDirection *= crouchSpeed;
             isCrouching = true;
         }
         
         if(Input.GetButtonUp("Crouch"))
         {
             //Reset height and center after ducks
             controller.height = normalHeight;
             controller.center.y = controller.height/2;
             isCrouching = false;
         }
         
         if(Input.GetButtonUp("Run"))
         {
             isRunning = false;
         }
         
         //Apply gravity to end jump, enable falling, and make sure he's touching the ground
         moveDirection.y -=gravity * Time.deltaTime;
         
         //Move and rotate the controller
         var flags = controller.Move(moveDirection * Time.deltaTime);
         controller.transform.Rotate(rotateDirection * Time.deltaTime, rotateSpeed);
         grounded = ((flags & CollisionFlags.CollidedBelow) != 0);
     }
 }
 
 //----------------------------------------------------
 function IsMoving()
 {
     return moveDirection.magnitude > 0.5;
 }
 
 function IsRunning()
 {
     return isRunning;
 }
 
 function IsCrouching()
 {
     return isCrouching;
 }
 
 function IsGrounded()
 {
     return grounded;
 }
 

Animation:

 function Update() 
 {
     //On  the ground animations
     if(playerController.IsGrounded())
     {
         animation.Blend("FallDown", 0, 0.2);
         animation.Blend("Jump", 0, 0.2);
 
         //If Running
         if(playerController.IsRunning())
         {
             animation.CrossFade("Run", 0.5);
             animation["Run"].speed = 4.4;
             nextPlayIdle = Time.time + waitTime;
         }
         else if(playerController.IsCrouching())
         {
             animation.CrossFade("Crouch", 0.2);
             nextPlayIdle = Time.time + waitTime;
         }
         //Fade in Walk
         else if(playerController.IsMoving())
         {
             animation.CrossFade("Walk", 0.5);
             animation["Walk"].speed = 3.2;
             nextPlayIdle = Time.time + waitTime;
         }
         //Fade out walk and run else
         else
         {
             animation.Blend("Run", 0.0, 0.3);
             animation.Blend("Walk", 0.0, 0.3);
             animation.Blend("Crouch", 0.0, 0.3);
             if(Time.time > nextPlayIdle)
             {
                 nextPlayIdle = Time.time + waitTime;
                 PlayIdle();
             }
         }    
     }
     //In air animations
     else
     {
         if(Input.GetButton("Jump"))
         {
             animation.CrossFade("Jump");
         }
         
         if(!playerController.IsGrounded())
         {
             animation.CrossFade("FallDown", 0.5);
         }
     }
     
     //Test for idle
     if(Input.anyKey)
     {
         if(moveDirection.magnitude <= 0)
         {
             animation.CrossFade("Idle");
         }
     }
 }
Comment
Add comment · Show 1
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 CyberArtist · Aug 12, 2014 at 04:24 PM 0
Share

Update:

     animation["Crouch"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Loop;
     animation["Jump"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Once;
     animation["FallDown"].wrap$$anonymous$$ode = Wrap$$anonymous$$ode.Once;

Turns out that the Wrap$$anonymous$$ode was causing the Jump animation to play only when I press the Jump key the first time. So I changed it form ClampForever to Once. Yet, I still don't know how to fix the FallDown animation playing directly after Jump, when it should only play when my character is touching something solid.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by CyberArtist · Aug 13, 2014 at 01:05 AM

Update:

Got rid of this:

         animation.Blend("FallDown", 0, 0.2);
         animation.Blend("Jump", 0, 0.2);
         animation["FallDown"].speed = 3;
         animation["Jump"].speed = 3;
 

Got rid of the remaining issues I was having.

Comment
Add comment · 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

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

2 People are following this question.

avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Animation in Unity 4.3 0 Answers

Animation spins wildly after completed 0 Answers

How can I reassign animation curves to play on a child object (instead of through parent)? 1 Answer

Problem with animation: they always start at the same rotation!! 1 Answer


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