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 Keudn · Oct 11, 2013 at 04:05 AM · animationplaycrouchsprint

Cannot get sprint animation to play when crouch works fine?

I have a script I wrote to play the walk animation when walking, sprint when sprinting, etc. I have it set up to where there are walk, crouch, and sprint variables all set to 0 and when you press the w, c, or left shift buttons the variables are changed to 1. The game then looks at the variables and depending on which ones are 1 and which are 0 plays the correct animation. For example, if I wanted to play the crouch animation it looks for the walk variable being equal to the couch variable, and it also looks to see if the crouch variable is 1. This means you have to be pressing BOTH the w and c keys to play the animation (the animation only plays when the character is crouched and is moving forward). I did the EXACT same code for the sprint animation as well and only changed crouch to sprint and the crouch animation to the sprint animation so it does the exact same thing but with sprinting vs crouching and IT DOES NOT WORK. The animation will not play, even though the code is exactly the same save for sprint substituted in for crouch where needed. In unity, the variables for walking and sprinting both change to 1 like they should and revert back to 0 when the keys are released (which is EXACTLY the same as when crouching), but only the crouch animation works, not the sprint. Can anyone find where I went wrong in the code and how to fix it so I can sprint properly???

 function OnEnable()
 {
     animation.Stop("sprintAnimation");
     animation.Stop("walkAnimation");
     animation.Stop("crouchAnimation");
 }
 
 var crouch : float;
 var walk : float;
 var sprint : float;
 
 function Start () 
 {
     crouch = 0;
     walk = 0;
     sprint = 0;
 }
 
 function Update ()
 {
     if(Input.GetKeyDown("space"))
          {
               animation.Play("jumpAnimation", PlayMode.StopAll);
          }
          
     if(Input.GetKeyDown("w"))
     {
         walk = 1;
     }
     
     if(Input.GetKeyDown("c"))
     {
         crouch = 1;
     }
     
     if(Input.GetKeyDown("left shift") || Input.GetKeyDown("right shift"))
     {
         sprint = 1;
     }
     
     
     if(walk == crouch && crouch == 1)
     {
         animation.Play("crouchAnimation", PlayMode.StopAll);
     } if(walk == sprint && sprint == 1)
     {
         animation.Play("sprintAnimation", PlayMode.StopAll);
     } if(walk == 1 && crouch == 0)
     {
         animation.Play("walkAnimation", PlayMode.StopAll);
     }
     
     
     
     
     if(Input.GetKeyUp("w"))
     {
         walk = 0;
         animation.Stop("walkAnimation");
     }
     
     if(Input.GetKeyUp("c"))
     {
         crouch = 0;
         animation.Stop("crouchAnimation");
     }
     
     if(Input.GetKeyUp("left shift"))
     {
         sprint = 0;
         animation.Stop("sprintAnimation");
     }
     
 }
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 Keudn · Oct 11, 2013 at 04:06 AM 0
Share

Note: I changed the left shift keybind to f incase the left shift was messing something up and nothing. I also replaced the working crouch animation with the sprint animation and it worked perfectly fine, so it isn't the sprinting animation

0 Replies

· Add your reply
  • Sort: 

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

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Run Sprint animation and stop it when button is released 1 Answer

Not playing entire animation when it is called. 1 Answer

Help With Animation Play Back - Reverse 1 Answer

Playing animation when GameObject is destroyed 2 Answers

Can the animation editor create local rotational data? 3 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