Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Tonba · Jan 09, 2020 at 09:22 AM · animatormobileanimator controllerjoysticklandscape

If mobile joystick is moved , then animation transforms from idle to walk?

So i need help in my project.

Im trying to recognize joystick movement and then switching unity animations based on it. How can i do this? I have set the bool parameter "isWalking" correctly into animator with transactions.

 // Update is called once per frame
 void Update()
 {
     if (Input.GetKey(""){  // IN HERE I AM SUPPOSED TO CONNECT TO JOYSTICK MOVEMENT 
         anim.SetBool("isWalking", true);
     }
     else
     {
         anim.SetBool("isWalking", false);
     }

 }

}

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 Tonba · Jan 09, 2020 at 09:38 AM 0
Share

soo like this? I get the error "cant convert from float to bool" I am a complete novice so it makes things hard haha

 void Update()
 {
     
     if (Input.GetAxis("Horizontal"){  // IN HERE I A$$anonymous$$ SUPPOSED TO CONNECT TO JOYSTIC$$anonymous$$ $$anonymous$$OVE$$anonymous$$ENT 
         anim.SetBool("isWalking", true);
     }
     else
     {
         anim.SetBool("isWalking", false);
     }

 }

2 Replies

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

Answer by ZozeR · Jan 09, 2020 at 09:31 AM

Try using GetAxis instead of getkey. because as far as i know getkey is for getting keyboard input and you have to use keycodes. getaxis is much better since its checking for a lot of input types and highly configurable. you need to use it like this however;

 if (Input.GetAxis("Horizontal") > 1)
 //right
 else if (Input.GetAxis("Horizontal") < 1)
 //left
 
 //or
 if(Input.GetAxis("Horizontal") != 0)
 //move left right

https://docs.unity3d.com/Manual/ConventionalGameInput.html https://docs.unity3d.com/ScriptReference/Input.GetAxis.html

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

Answer by Tonba · Jan 09, 2020 at 09:58 AM

Hey,

my code is now this:

     if (Input.GetAxis("Horizontal") > 1 ){ 
         anim.SetBool("isMoving", true);

     }
     else if (Input.GetAxis("Horizontal") < 1)
     { 
         anim.SetBool("isMoving", false);
     }

 }

}

Still no animation changing from idle -> walk.. :/ i have set bool parameter from animator with transactions , bool isMoving true -> goes to walk animation, and if bool is false -> goes back to idle.. Any ideas ?

Comment
Add comment · Show 2 · 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 ZozeR · Jan 09, 2020 at 10:53 AM 0
Share

if horizontal input > 0 it means right input, if its < 0 it means left input.

 if (Input.GetAxis("Horizontal") != 0)
 {
     anim.SetBool("is$$anonymous$$oving",true);
 }
 else
     anim.SetBool("is$$anonymous$$oving",false);

This is the correct way. however i cannot see why it shouldnt work. are you sure unity recognizes your joystick? maybe use Debug.Log(Input.GetAxis("Horizontal")) somewhere to check if it can. if it can; it's probably a problem from your animator. if it can't, check these out; https://docs.unity3d.com/ScriptReference/Input.GetAxis.html https://www.youtube.com/watch?v=p-3S73$$anonymous$$aDP8

avatar image Tonba ZozeR · Jan 10, 2020 at 09:54 AM 0
Share

Hey man, thank you for your help!

The above code didnt work, i debugged it as u did advice and my game didnt regocnize any movement. i managed to solve my problem and now my animations are playing well when joystick is moved! Heres the code that works:

     if (joystick.Horizontal != 0)
     {
         anim.SetBool("is$$anonymous$$oving", true);
     }
     else
     {
         anim.SetBool("is$$anonymous$$oving", false);
     }


     // Vertical movement detection, if detected setting bool to true -> Animator plays the next animation
     if (joystick.Vertical != 0)
     {
         anim.SetBool("is$$anonymous$$oving", true);
     }
     else
     {
         anim.SetBool("is$$anonymous$$oving", false);
     }

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

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

Related Questions

Animtion looping if joystick is held 0 Answers

Change the position of the Joystick by tap 2 Answers

How to get Animator Tab to Work with blender model 0 Answers

how to shoot with joystick 0 Answers

Triggering Another GameObject's Animator Triggers 0 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