2
\$\begingroup\$

I'm using an Xbox 360 controller on Windows 10 with Unity, and the maximum values have the opposite sign as the rest of that side. For example, if I tilt the stick up, I get values from 0.1 to 0.99, but then I get a -1 when the stick is at maximum. Have I configured it to be this way by mistake? I have reproduced the issue in a clean project and using another controller.

Input configuration

void Update () {
    float pitch = Input.GetAxis("Vertical");
    Debug.Log (pitch);
}

enter image description here


I have discovered that if the axis is inverted (i.e. not as shown in the image) then returned values have expected signs. I will add this workaround as an answer for anyone else who may encounter this problem, but I will refrain from accepting it to allow for answers addressing the root cause.

\$\endgroup\$
  • \$\begingroup\$ That's really odd. Might be a Unity bug. \$\endgroup\$ – Draco18s Dec 31 '17 at 1:27
  • \$\begingroup\$ Hm! I've never seen this before. Are you able to reproduce the issue with different controllers, or in a fresh project? \$\endgroup\$ – DMGregory Dec 31 '17 at 3:56
  • \$\begingroup\$ @DMGregory Yes, I have reproduced it with a different controller (but I only have one USB wireless dongle) and in a fresh project. :/ \$\endgroup\$ – Tashus Dec 31 '17 at 23:10
  • \$\begingroup\$ Have you checked the joystick calibration in the control panel? For example: maketecheasier.com/calibrate-game-controller-windows10 \$\endgroup\$ – Ed Marty Jan 1 '18 at 3:02
  • \$\begingroup\$ @EdMarty Thanks for the suggestion, but calibration didn't change it. The issue isn't present in control panel. :/ \$\endgroup\$ – Tashus Jan 1 '18 at 22:23
0
\$\begingroup\$

I had previously discovered a workaround that gave me reasonable behavior but did not reveal the underlying problem. I have revisited the project and have determined the root cause.

Two axes were named "Horizontal".

It seems that the InputManager by default has two axes named "Horizontal" and two axes named "Vertical." Deleting one of the sets completely solved the issue.


The previous solution:

Setting the axis to inverted causes the returned values to behave in a sensible way. Now if I tilt the stick up, I get values from -0.1 to -0.99 and -1 when the stick is at maximum, and I get values from 0.1 to 0.99 and 1 when I tilt the stick down. I can just as easily write my script expecting an inverted axis, so this allows me to continue. Unfortunately I still don't know what is causing the odd behavior when the axis isn't inverted.

\$\endgroup\$
  • 1
    \$\begingroup\$ when inverted, what happens as the stick moves to maximum down? \$\endgroup\$ – Stephan Oct 30 '18 at 15:45
  • \$\begingroup\$ @Stephan Edited. Unfortunately I have not worked on this project for a while, so I am not sure whether I can still reproduce this behavior. \$\endgroup\$ – Tashus Oct 30 '18 at 15:51
  • 1
    \$\begingroup\$ Should be easy enough to test. I'll spin one up later this afternoon, and get back to you \$\endgroup\$ – Stephan Oct 30 '18 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.