Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Incorrect Values from Input.GetAxis

Discussion in 'Linux' started by Jseg, Nov 6, 2016.

  1. Jseg

    Jseg

    Joined:
    Jul 29, 2016
    Posts:
    13
    Hi!!

    I need the gamepad Input on my game, and I'm trying the Input.getAxis("Horizontal") function and the documentation says that returns a value from -1 to 1, 0 is the central value, when I not move the stick left or right. Well, I'm on linux-editor on mint 17.3 and all is ok, the joystick configuration on mint is correct, but in Unity I having a 0 to top-left-moved and 1 to top-right-moved joystick on my gamepad (logitech rumblepad2). Center is 0.56.

    What is the problem?? Is a linux editor problem, is a bad Unity configuration...
     
  2. Odd-Redesign

    Odd-Redesign

    Joined:
    Jul 26, 2013
    Posts:
    134
    I can confirm that this happens on too on my xbox 360 controller. Depending on the current mood of the Editor/Player, the gamepad axis will act in a weird interval between -1 and 1. Like you said, sometimes it's 0 and 1, but there were several occasions where I had random values like -0.5 and 1, or -0.2 to 0.2.

    Since I implemented a mechanism that let's the player run instead of walk only when the Input Value is higher than 0.9f, this was problematic because running was impossible on these values.

    Restarting the game until the controller works is a thing and shows that it isn't a configuration error with the gamepad in general. The number of restarts you need to get it working is random.

    I implemented a workaround some time ago to be able to work with the new maximums, maybe it'll help you bypass the calibration error.

    Code (CSharp):
    1.  
    2. private float minimumX = -0.1f;
    3. private float maximumX = 0.1f;
    4.  
    5. private float minimumY = -0.1f;
    6. private float maximumY = 0.1f;
    7.  
    8. [...]
    9.  
    10. float verticalInput = ManagesInput.getInstance ().getInput (InputCases.MOVE_UP_DOWN);
    11. float horizontalInput = ManagesInput.getInstance ().getInput (InputCases.MOVE_LEFT_RIGHT);
    12.  
    13. if (horizontalInput > maximumX) {
    14.   maximumX = horizontalInput;
    15. }
    16.  
    17. if (horizontalInput < minimumX) {
    18.   minimumX = horizontalInput;
    19. }
    20.  
    21. if (verticalInput > maximumY) {
    22.   maximumY = verticalInput;
    23. }
    24.  
    25. if (verticalInput < minimumY) {
    26.   minimumY = verticalInput;
    27. }
    28.  
    29. if (horizontalInput >= maximumX) {
    30.   horizontalInput = 1;
    31. }
    32.  
    33. if (horizontalInput <= minimumX) {
    34.   horizontalInput = -1;
    35. }
    36.  
    37. if (verticalInput >= maximumY) {
    38.   verticalInput = 1;
    39. }
    40.  
    41. if (verticalInput <= minimumY) {
    42.   verticalInput = -1;
    43. }
    44.  
    45. Vector3 currentPosition = controllerSettings.currentPosition;
    46. float stepWidth = controllerSettings.controlledSettings.stepWidth;
    47.  
    48. Vector3 forward = controllerSettings.controlledSettings.forwardDirection.normalized;
    49. Vector3 right = controllerSettings.controlledSettings.rightDirection.normalized;
    50.  
    51. float intensityFactorY = 0.5f;
    52. if (Mathf.Abs(verticalInput) > (0.9f)) {
    53.   intensityFactorY = 1;
    54. }
    55.  
    56. float intensityFactorX = 0.5f;
    57. if (Mathf.Abs(horizontalInput) > (0.9f)) {
    58.   intensityFactorX = 1;
    59. }
    60.  
    61. if (Mathf.Abs(horizontalInput) > (0.6f) && Mathf.Abs(verticalInput) > (0.6f)) {
    62.   intensityFactorY = 1;
    63.   intensityFactorX = 1;
    64. }
    65.  
    66. intensityFactorY = (intensityFactorY * verticalInput) * ManagesGame.getInstance().controlSettings.sensitivity;
    67. intensityFactorX = (intensityFactorX * horizontalInput) * ManagesGame.getInstance().controlSettings.sensitivity;
    68.  
    69. Vector3 direction = Vector3.zero;
    70. direction += forward * intensityFactorY;
    71. direction += right * intensityFactorX;
    72.  
    73. Vector3 targetPosition = currentPosition + (direction * stepWidth);
    74.  
     
  3. longroadhwy

    longroadhwy

    Joined:
    May 4, 2014
    Posts:
    1,548
    What Linux distro (Ubuntu/Fedora,etc) are you using? Also what version of Linux are you using?
     
  4. Odd-Redesign

    Odd-Redesign

    Joined:
    Jul 26, 2013
    Posts:
    134
    It's somewhat hidden in his text, but he stated that he's using Linux Mint 17.3.

    That should make it kernel version 3.19 per default and 4.20 if installed through the repositories.
     
  5. Jseg

    Jseg

    Joined:
    Jul 29, 2016
    Posts:
    13
    Yes, I'm using Mint Xfce 17.3 with 3.19.0-32-generic kernel. I tried newer versions of linux (Ubuntu, mint...) with the lastest kernels but Unity and specially Monodevelop works very bad, launching a lot of errors, is stressful. With Mint 17.3 all works ok, but on some times I need to restart the editor because the window is freezed, i saw this issue specially when I move the objects through the scene.

    I "solved" this problem with joystick input drawing a virtual joystick (from asset store), in fact, I'm making an android game, I need the virtual joystick because the game is GTA1 style, with upper view.

    I appreciate the comments but I don't like making "patches" for this kind of problems, simply I'm using the keyboard for test purposes on PC, is sufficient for me.