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 DustingVitamins · Jun 26, 2013 at 05:55 PM · inputhorizontal

Problems with horizontal input. 0 and -1 both= false.

My object rotates and transform perfectly when I use getkey and press right and left. I wanted to switch to Unity's input feature so I could have the novelty of using a 360 controller. So choosing the Horizontal, I made it so that positive=right and negative=left. As I read in the reference. The horizontal axis will give from -1 to 1 and 0 is neutral. When I run this, My object starts turning left. Which means its already false which suggests that 0=false. And since Getbutton is giving me a boolean, I am not sure how I can have the game know the difference between no input and negative input. Do I have to adjust the sensitivity? To clarify, the commented out getkeys work and I am sure I could just add an "or" to each if statement and find and input the joy button for the 360 controller but that is not elegant.

    if(Input.GetButton("Horizontal")==true)
         //if(Input.GetKey("right"))    
             {
           //if(!Input.GetKey("left"))
             //if(Input.GetButton("Horizontal")=true)
                 {
                     forwardv.x=(Mathf.Cos(-0.1f)*temp2.x)-(Mathf.Sin(-0.1f)*temp2.y);
                     forwardv.y=(Mathf.Sin(-0.1f)*temp2.x)+(Mathf.Cos(-0.1f)*temp2.y);
                     transform.Rotate(0,0,(float)(-0.1*180/Mathf.PI));
                 }
             }    
             
         //if(Input.GetKey("left"))
         if(Input.GetButton("Horizontal")==false)
             {
                 //if(!Input.GetKey("right"))
                         //if(Input.GetButton("Horizontal")!=true)
                 {
                     forwardv.x=(Mathf.Cos(0.1f)*temp2.x)-(Mathf.Sin(0.1f)*temp2.y);
                     forwardv.y=(Mathf.Sin(0.1f)*temp2.x)+(Mathf.Cos(0.1f)*temp2.y);
                     transform.Rotate(0,0,(float)(0.1*180/Mathf.PI));
                 }
             }    
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
1

Answer by robertbu · Jun 26, 2013 at 06:20 PM

The code here is obviously wrong because you are comparing Input.GetButton("Horizontal") to 'true' rather than using values in the -1 to 1 range. Assuming you don't want a range of values, but just true/false, just do something like:

 if(Input.GetButton("Horizontal") < -.1)

If you are using a joystick and your character is walking with a dead stick, consider upping the Dead setting for "Horizontal". Go to Edit/Project Settings Input.

Comment
Add comment · Show 3 · 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 DustingVitamins · Jun 26, 2013 at 08:44 PM 0
Share

unfortunately I cannot compare a bool with a double. Alternatively, I used GetAxis and applied something close to what you suggest and it worked beautifully on my controller but it ruined my keyboard controls. If i press left on the keyboard the object rotates indefinitely in that direction. I am thinking I need to set the float variable that holds the value from GetAxis to 0 at some point to stop the permanent spinning but I am not sure where in the above code to apply it.

avatar image robertbu · Jun 26, 2013 at 10:21 PM 0
Share

It is difficult to figure out your problem without seeing the code. Post your revised code as a comment or revise the code in your original question.

avatar image DustingVitamins · Jun 27, 2013 at 01:55 AM 0
Share

Axis is a float that I store the axis information into. I guess because the controller analog has a deadzone (which equals zero) and allows for ideal object movement. But how do I tell the right and left buttons to return to zero after use.

     if(axis>0)
     //if(Input.Get$$anonymous$$ey("right"))    
         {
             
         
             //if(!Input.Get$$anonymous$$ey("left"))
         //    if(Input.GetButton("Horizontal")=true)
             {
                 forwardv.x=($$anonymous$$athf.Cos(-0.1f)*temp2.x)-($$anonymous$$athf.Sin(-0.1f)*temp2.y);
                 forwardv.y=($$anonymous$$athf.Sin(-0.1f)*temp2.x)+($$anonymous$$athf.Cos(-0.1f)*temp2.y);
                 transform.Rotate(0,0,(float)(-0.1*180/$$anonymous$$athf.PI));
                 
             }
         }    
         
     //if(Input.Get$$anonymous$$ey("left"))
     if(axis<0)
         {
             //if(!Input.Get$$anonymous$$ey("right"))
             //if(Input.GetButton("Horizontal")!=true)
             {
                 forwardv.x=($$anonymous$$athf.Cos(0.1f)*temp2.x)-($$anonymous$$athf.Sin(0.1f)*temp2.y);
                 forwardv.y=($$anonymous$$athf.Sin(0.1f)*temp2.x)+($$anonymous$$athf.Cos(0.1f)*temp2.y);
                 transform.Rotate(0,0,(float)(0.1*180/$$anonymous$$athf.PI));
                 
             }
         }    
     
         
             axis=Input.GetAxis("Horizontal");

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

Adapting Horizontal and Vertical movement to New Input System? 0 Answers

How can I make GUI button send an input message when I press it? 0 Answers

The value of Input.GetAxis("Horizontal") gets stuck when Xbox controller is disconnected... 0 Answers

changing a float number by moving arrows (horizontal and vertical input)? 1 Answer

Horizontal Input showing random decimal when not pressing anything 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