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
1
Question by Calisthene · Jan 28, 2015 at 07:09 PM · animationjavascriptanimatoraxis

Playing sprint animation with vertical axis?

So I have made this JS script that works fine with walking. When the vertical axis is 0.01 or higher it goes from the idle to the walking animation.

The question is, how do I get it to play a sprint animation this way? Any other way is also fine aslong as it's useable in this script.

I use the parameters 'Walking' and 'Sprinting'.

 #pragma strict
 internal var animator : Animator;
 var hor : float;
 var ver : float;
 
 function Start () {
 
     animator = GetComponent(Animator);
 }
 function Update () {
 
     hor = Input.GetAxis("Horizontal");
     ver = Input.GetAxis("Vertical");
 }
 
 function FixedUpdate() {
 
     animator.SetFloat("Walking", ver);
     animator.SetFloat("Sprinting", ver);
 }    


Thanks!

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 Agoras · Jan 28, 2015 at 07:58 PM

The quickest way to get that to work in this script is probably to add a couple if statements where you are setting the floats. Something along the lines of: if(ver > 0.01 && ver <= 0.7) do Walking and if(ver >0.7) do Sprinting

That said I would suggest sending the ver float to the animator once as "speed", and handling the range for speed in the animator controller with transitions or a blend tree.

Comment
Add comment · Show 4 · 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 Calisthene · Jan 29, 2015 at 12:46 PM 0
Share

Well now I have this and it doesnt do anything anymore!

 #pragma strict
  
 internal var animator : Animator;
 var hor : float;
 var ver : float;
 
 function Start () {
 
    animator = GetComponent(Animator);
 }
 function Update () {
 
     hor = Input.GetAxis("Horizontal");
     ver = Input.GetAxis("Vertical");
 }
 
 function FixedUpdate() {
 
   if(ver >= 0.01 && ver <= 0.7)
   {
    animator.SetFloat("Walking", ver);
   }
    if(ver >= 0.7)
   {
    animator.SetFloat("Sprinting", ver);
   }
 }    
avatar image meat5000 ♦ Calisthene · Jan 29, 2015 at 12:45 PM 0
Share

What happens at exactly 0.7?

avatar image Calisthene · Jan 29, 2015 at 12:58 PM 0
Share

Nothing, but a tutorial I looked at it did it exactly the way I had the code on first post. Tho I feel like it can't recognize sprinting with vertical axis cause in the end walking and sprinting has the same vertical axis.

Do you have any other way?

avatar image meat5000 ♦ · Jan 29, 2015 at 01:01 PM 0
Share

Its just you have both

 ver <= 0.7

and

 ver >= 0.7

You will need to remove the = from one of them. (You've done it in your text but not in your code).

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to call a animation to transition to the next. 0 Answers

How To Play Animation 1 Answer

2D Animation does not start 1 Answer

Animator Trigger Not Working 1 Answer

Animator preventing correct spawn position? 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