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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Controller joystick only returns 8 directions (Bug?)

Discussion in 'Input System' started by collinpatrick15, May 30, 2019.

  1. collinpatrick15

    collinpatrick15

    Joined:
    Nov 7, 2018
    Posts:
    35
    As the title says, I'm only able to get 8 directions from the joysticks.
    [1,0]
    [0,1]
    [-1,0]
    [0,-1]
    [0.7, 0.7]
    [0.7, -0.7]
    [-0.7, 0.7]
    [-0.7, -0.7]
    and of course [0, 0]
    Is anyone else getting this issue or am I just being an idiot?

    This is the generated code:
    Code (CSharp):
    1.             ""bindings"": [
    2.                 {
    3.                     ""name"": ""Left Stick"",
    4.                     ""id"": ""fa27b3f9-4c13-4f0a-8b27-7486dd640241"",
    5.                     ""path"": ""2DVector"",
    6.                     ""interactions"": """",
    7.                     ""processors"": """",
    8.                     ""groups"": """",
    9.                     ""action"": ""Movement"",
    10.                     ""isComposite"": true,
    11.                     ""isPartOfComposite"": false,
    12.                     ""modifiers"": """"
    13.                 },
    14.                 {
    15.                     ""name"": ""up"",
    16.                     ""id"": ""f410eab2-de72-4ecc-932e-9e223baae5f9"",
    17.                     ""path"": ""<Gamepad>/leftStick/up"",
    18.                     ""interactions"": """",
    19.                     ""processors"": """",
    20.                     ""groups"": ""Controller"",
    21.                     ""action"": ""Movement"",
    22.                     ""isComposite"": false,
    23.                     ""isPartOfComposite"": true,
    24.                     ""modifiers"": """"
    25.                 },
    26.                 {
    27.                     ""name"": ""down"",
    28.                     ""id"": ""b0da6f0d-ecd0-4a6f-af3c-47febd5acf84"",
    29.                     ""path"": ""<Gamepad>/leftStick/down"",
    30.                     ""interactions"": """",
    31.                     ""processors"": """",
    32.                     ""groups"": ""Controller"",
    33.                     ""action"": ""Movement"",
    34.                     ""isComposite"": false,
    35.                     ""isPartOfComposite"": true,
    36.                     ""modifiers"": """"
    37.                 },
    38.                 {
    39.                     ""name"": ""left"",
    40.                     ""id"": ""e139f5c7-d7a7-4ef1-8061-b0e5c8224078"",
    41.                     ""path"": ""<Gamepad>/leftStick/left"",
    42.                     ""interactions"": """",
    43.                     ""processors"": """",
    44.                     ""groups"": ""Controller"",
    45.                     ""action"": ""Movement"",
    46.                     ""isComposite"": false,
    47.                     ""isPartOfComposite"": true,
    48.                     ""modifiers"": """"
    49.                 },
    50.                 {
    51.                     ""name"": ""right"",
    52.                     ""id"": ""40555fc7-b1fc-4557-8201-2a0d3f081969"",
    53.                     ""path"": ""<Gamepad>/leftStick/right"",
    54.                     ""interactions"": """",
    55.                     ""processors"": """",
    56.                     ""groups"": ""Controller"",
    57.                     ""action"": ""Movement"",
    58.                     ""isComposite"": false,
    59.                     ""isPartOfComposite"": true,
    60.                     ""modifiers"": """"
    61.                 },
    This is my code:
    Code (CSharp):
    1. public void UpdatePosition(InputAction.CallbackContext context)
    2.     {
    3.         //Convert vector2 direcion to vector3 direction
    4.         Debug.Log(context.ReadValue<Vector2>());
    5.         Vector3 _moveDirection = new Vector3(context.ReadValue<Vector2>().x, 0, context.ReadValue<Vector2>().y);
    6.  
    7.         //transform direction to camera
    8.         _moveDirection = Camera.main.transform.TransformDirection(_moveDirection);
    9.         _moveDirection.y = 0;
    10.         //_moveDirection.Normalize();
    11.  
    12.         //apply speed and rotation
    13.         _currentSpeed = Mathf.Lerp(_currentSpeed, _moveSpeed(), 3f * Time.deltaTime);
    14.  
    15.         _moveDirection *= _currentSpeed;
    16.         transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(_moveDirection), 3f * Time.deltaTime);
    17.         _player.Move(_moveDirection * Time.deltaTime);
    18.     }
    19.  
    Code (CSharp):
    1.     public void OnMovement(InputAction.CallbackContext context)
    2.     {
    3.         _movementController.UpdatePosition(context);
    4.  
    5.         if (context.canceled)
    6.         {
    7.             _movementController.StopMoving(context);
    8.         }
    9.     }
    10.  
     
  2. collinpatrick15

    collinpatrick15

    Joined:
    Nov 7, 2018
    Posts:
    35
    After looking around for a while. I read on another post that I can set the binding to just gamepad/leftStick instead of a 2D vector with up/down/left/right binding. to get the left stick option, I had to manually change the generated JSON file with "path"": ""<Gamepad>/leftStick"" instead of whatever it was before. This seems to fix my issue but I'm not sure why this isn't an option in the binding path dropdown.
     
  3. pgpais

    pgpais

    Joined:
    Nov 23, 2015
    Posts:
    12
    As of today, you can just add a regular binding and choose the whole analog stick as your input (instead of a composite 2D input).

    upload_2019-7-1_20-18-10.png
     

    Attached Files: