Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 NDraskovic · Sep 28, 2015 at 06:12 PM · c#inputinput.getaxiscontrollers

Game doesn't recognize X-axis input from XBox 360 controller

I have a problem with the usage of XBox controller in Unity game. I connected the controller to the PC and it works fine, I also managed to use it in the game itself - I'm using "A" button to fire and Start to start the game and they work properly. However the game doesn't recognize the x-axis movement (y-axis would probably have the same problem but we don't use it in our game). I'm not sure if the problem is in the input settings or my code. This is how the Horizontal movement is defined in the game:

alt text

This is the code that handles the movement:

  float x = Input.GetAxis("Horizontal");
         Vector3 newPosition = new Vector3(transform.position.x + x*playerXMoveSpeed, 0, 0);            
         newPosition.y = transform.position.y;
         newPosition.z = 0;           
 
         transform.position = Vector3.Lerp(transform.position, newPosition, playerXMoveSpeed * Time.deltaTime);
 
         var limit = animator.SpriteRenderer.bounds.extents;
         if (transform.position.x - limit.x < leftBorder)
         {
             var capped = transform.position;
             capped.x = leftBorder + limit.x;
             transform.position = capped;
         }
         else if (transform.position.x + limit.x > rightBorder)
         {
             var capped = transform.position;
             capped.x = rightBorder - limit.x;
             transform.position = capped;
         }
 
         OnMove(gameObject);

All variables are more or less self explanatory, the OnMove is a delegate that just applies the transform to the gameObject in question. The entire code is inside a void method called Move(). That method is called inside an if statement:

 if ((Input.GetAxis("Horizontal") != 0.0f || Input.GetButtonDown("Horizontal")))
         {
             Move();
         }

Like I said, the game recognizes the other buttons, but not the x-axis, it doesn't move the character. The Input.GetButtonDown is there just so keyboard input would be supported also (and it works properly). Can you see the problem with this code or settings? Please advise.

horizontalsettings.png (46.3 kB)
Comment
Add comment · Show 3
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 NDraskovic · Sep 28, 2015 at 06:44 PM 0
Share

Just a quick update - when I switch to the 4th axis (the right side joystick) it works as it should, why is this happening?

avatar image vintar · Sep 28, 2015 at 06:54 PM 0
Share

http://wiki.unity3d.com/index.php?title=Xbox360Controller

$$anonymous$$aybe that will help some.

avatar image NDraskovic · Sep 28, 2015 at 07:07 PM 0
Share

Yeah, that's what I used in the first place, and like I said everything except the x-axis works, 4th axis works perfectly, key mappings like "A"=0 and "Start"=7

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Kornikolia · Sep 28, 2015 at 07:51 PM

Maybe it will be easy for you to use UnityStandardAssets.CrossPlatformInput ?

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 NDraskovic · Sep 28, 2015 at 07:53 PM 0
Share

Honestly, never heard of it. Thanks, I'll give it a look.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

GetAxisRaw defaulting to -1 instead of 0 1 Answer

Input.GetAxis not returning 0 when keyboard is idle 1 Answer

Using Default Input for mobile platform. 0 Answers

Input returns 0 until released and pressed again if held down before start of scene 0 Answers

Multiple Cars not working 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