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

New input system joystick values all the same?

Discussion in 'Input System' started by Unlimited_Energy, Jan 6, 2022.

  1. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    Hi, I might be missing something on how the values work for the joystick but I was trying to hook up a blendtree animation to the joystick values for left and right and I figured the result would be something like, left return negative1 and right is positive 1 or something like that, but I noticed that all of the values are the same for every direction at their maximum values.

    Is there a way to interpret that 1 left and 1 right are different directions in the new input system so that I can correlate that to my animations blendtree?

    podracer.PNG
     
  2. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    Maybe you can do something like that:

    upload_2022-1-6_16-34-22.png

    And then:

    upload_2022-1-6_16-34-53.png

    Maybe this works too? I would try along these lines:

    upload_2022-1-6_16-35-49.png

    All I know is that I'm using that way for gamepad and it works fine.
     
    Unlimited_Energy likes this.
  3. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    what are you getting back from Vector3(.ReadValue<float>(), 0, 0);
     
  4. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    i get it now. I see where I did not understand the logic. Its from 0 TO 1 on the left and from 0 to 1 on the right, and top and bottom. You specify the left control you set up in the action inputs as left or right and read from 0 to 1 the value. Thats why there is no negative number...
     
  5. dlorre

    dlorre

    Joined:
    Apr 12, 2020
    Posts:
    700
    Well, you can have negative and positive values with Vector2:

    Code (CSharp):
    1.         private void ChangeDirection(InputAction.CallbackContext context)
    2.         {
    3.             var value = context.ReadValue<Vector2>();
    4.  
    5.             if (Math.Abs(value.x) > Math.Abs(value.y))
    6.             {
    7.                 // horizontal
    8.                 if (value.x < 0)
    9.                 {
    10.                     // left
    11.                 }
    12.                 else
    13.                 {
    14.                     // right
    15.                 }
    16.             }
    17.             else
    18.             {
    19.                 // vertical
    20.                 if (value.y < 0)
    21.                 {
    22.                     // down
    23.                 }
    24.                 else
    25.                 {
    26.                     // up
    27.                 }
    28.             }
    29.  
    30.         }
    You can also check for both directions at the same time if you want.