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 HolBol · Oct 21, 2010 at 10:05 PM · animationverticalhorizontal

Get walk animation to play on horizontal and vertical axis presses.

I have this script:

function Update () { if (Input.GetAxis("Vertical")) {

animation.CrossFade("Walk"); } else { animation.CrossFade("Idle"); } if (Input.GetAxis("Horizontal")) { animation.CrossFade("Walk"); } else { animation.CrossFade("Idle"); } }

what i want to happen is that if the player presses either the horizontal or vertical axis buttons, to play the walk cycle, and if not, play the idle. However when i use this script it will play the walk on the horizontal key presses but not on the vertical ones. How do I solve this?

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

2 Replies

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

Answer by VS48 · Oct 21, 2010 at 10:19 PM

Your vertical input is completely ignored because your "if-else" block for horizontal input will always override what the vertical input did.

What you probably want is:

function Update () 
{
    if (Input.GetAxis("Vertical")) 
    {
        animation.CrossFade("Walk");
    }
    else if(Input.GetAxis("Horizontal")) 
    {
        animation.CrossFade("Walk");
    } 
    else 
    {
        animation.CrossFade("Idle");
    }
}

Or something similar

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 HolBol · Oct 21, 2010 at 10:26 PM 0
Share

cheers dude :)!

avatar image
0

Answer by Setzer · Mar 30, 2011 at 10:13 PM

function Update () 
{
    if (Input.GetAxis("Vertical") || Input.GetAxis("Horizontal")) 
    {
        animation.CrossFade("Walk");
    }    
    else 
    {
        animation.CrossFade("Idle");
    }
}

Same as above, honestly, except you only have one condition and one default. If you're unfamiliar with script, "||" means "OR".

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 HolBol · Apr 02, 2011 at 11:07 AM 1
Share

umm, this question was marked as answered 5 months ago.

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

No one has followed this question yet.

Related Questions

How can I play different animations depending on the direction my character is moving? 1 Answer

Play animation for horizontal and vertical movement? 1 Answer

Translate a game object on horizontal and vertical axis? 3 Answers

Vertically Stationary Camera for 2D? 0 Answers

Simple controls for a helicopter 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