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 knuckles209cp · Nov 08, 2013 at 03:57 AM · speedsprint

Sprint animation play ONLY when speed = 13

So i want my sprint animation to play when holding up AND shift , and once the maxwalk speed reaches 13 , the sprint animation plays ... I've been stuck on this for nearly 4 months now ....

 function Update ()
 {
 
 
    if(Input.GetButtonDown("sprint"))
    {
       isSprinting = true;
       ump.animation.Play("sprintAnimation");
       movement.maxForwardSpeed = 13;
       
 
 
      
  
    }
 if(Input.GetButtonUp("sprint"))
       {
           isSprinting = false;
            movement.maxForwardSpeed = 6;
            ump.animation.Stop("sprintAnimation");
            
       }
 
 
 }

I know this is wrong but i've tried my best , Any help will be appreciated :)

Comment
Add comment · Show 5
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 KuPAfoo · Nov 08, 2013 at 04:15 AM 0
Share

thanks for reviewing my post... here's my advice

the two statements appear repetitive... rather than checking if the button is released, why not make the else statement ALWAYS set sprinting to false?

don't forget to crossfade your animations if your using 3d.

and if you want sprint active ONLY if your speed is at 13 (meaning 13 and above) you should include that in your if statement.

if(Input.GetButtonDown("sprint") && movement.maxForwardSpeed>=13) { perform sprint animation } else { sprint=false; }

in this case the bool sprint isn't nessicary

avatar image knuckles209cp · Nov 08, 2013 at 05:43 AM 0
Share

Thank you alot :) , i will let you know if this works

avatar image knuckles209cp · Nov 08, 2013 at 06:52 AM 0
Share

Sorry ... i dont know how to put this..

avatar image Immanuel-Scholz · Nov 08, 2013 at 04:17 PM 0
Share

the two statements appear repetitive... rather than checking if the button is released, why not make the else statement ALWAYS set sprinting to false?

That is not true. GetButtonDown() and GetButtonUp() are true in the frame when the user presses/releases the button, not when he just holds the button down. Do not confuse them with "GetButton()"

avatar image KuPAfoo · Nov 08, 2013 at 05:15 PM 0
Share

In his code it appeared he wanted to sprint only if he had been moving in a forward velocity.once move speed reached 13 it would auto show the sprint animation. Ivy seen this in sonic unleashed when daytime sonic ran an uninterrupted course for x amount of time.

I never used the phrase "getbutton()". Thanks for revising my advice. As you noticed I didn't answer his question, but only commented to attempt helping him think another structure for his problem.

1 Reply

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

Answer by Immanuel-Scholz · Nov 08, 2013 at 04:16 PM

From your words, its not entirely clear to me what you want and what you currently have. Maybe you can rephrase your question, if the following is not correct:

So you want to start playing the animation "sprintAnimation" if both of the following is true:

  • The user presses the upward key

  • The user holds down shift

Also, together with starting "sprintAnimation", you want to set the maximum speed of the avatar to "13". (The speed is then probably used from somewhere else to actually move the character.)

Is this correct?

If so, first make sure that the following things are configured correctly:

  • You have a virtual button mapping for your key "sprint" in Edit/Project Settings/Input, which maps the main key to "right shift" and the alternative key to "left shift"

  • You have another axis mapping for your movement. Or you use the default setting of "Vertical" for that (should map to up/down arrow keys)

If that's taken care of, change your code to not only test for the keydown/up event on "sprint" but also on the axis key.

 if(Input.GetButton("sprint") && Input.GetAxis("Vertical") > 0.5f)
 ...
 if(!Input.GetButton("sprint") || Input.GetAxis("Vertical") <= 0.5f)

Please note that I do not use GetButtonDown/Up but instead GetButton. The *Down/Up version only returns true in the one single frame when the user presses/release the corresponding key. That is undesireable for you, since your user doesn't need to release/press the up-key and the shift-key in the same frame.

Comment
Add comment · Show 1 · 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 knuckles209cp · Nov 10, 2013 at 07:32 AM 0
Share

JESUS YOU LEGEND!!!!!!!!!!!!!!!! , I am VERY happy with what you said , you got everything correct and i am very thankful for that! Thumbs up

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

17 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 avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Why Isn't This Sprint Working? 1 Answer

Increase/reset speed on tilt 0 Answers

Scroll to change walk speed... 1 Answer

Increase speed of footsteps when sprinting? 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