Search Unity

Left Stick [GamePad] has only 8 directions

Discussion in 'Input System' started by vizgl, Mar 28, 2021.

  1. vizgl

    vizgl

    Joined:
    Nov 4, 2014
    Posts:
    61
    Hello everyone, I have using OnScreenStick to make virtual Joystick for mobile game.
    I add game pad LeftStick to the ControlPath:
    upload_2021-3-28_4-9-28.png
    No, how I understand, OnScreenStick will emulate game pad left stick.

    Then in the inputactions asset, I added this bindings:
    upload_2021-3-28_4-10-44.png

    Also Movement has this properties:
    upload_2021-3-28_4-19-36.png

    I generated GameInput class from inputactions asset.

    Code (CSharp):
    1.  
    2. private GameInput _gameInput;
    3.  
    4. void Awake()
    5. {
    6.    _gameInput = new GameInput();
    7.    _gameInput.Player.Enable();
    8. }
    9.  
    10. void Update()
    11. {
    12.    Vector2 gamePadAxis = _gameInput.Player.Movement.ReadValue<Vector2>();
    13.    _player.SetDirection(gamePadAxis);
    14. }
    15.  
    Now, when I move OnScreenStick, player rotate only by 45 degrees, 8 directions.
    How can I make it rotate in the full 0-360 range angles?

    P.S. I found some interesting thing. If I get xy values by this method. I get angles in the full range, but still has little dead zones in the angles 0, 90, 180, 270
    But, why code above is round angles by 45 degrees?
    Code (CSharp):
    1.     void Update()
    2.     {
    3.         float a = 0;
    4.  
    5.         Vector2Control control = stick.control as Vector2Control;
    6.  
    7.         a = Mathf.Atan2(control.y.ReadValue(), control.x.ReadValue()) / Mathf.PI * 360f;
    8.  
    9.         Debug.Log(a);
    10.     }
     
    Last edited: Mar 28, 2021
  2. vizgl

    vizgl

    Joined:
    Nov 4, 2014
    Posts:
    61
    Fixed, just add 2D Vector binding instead of Left Stick, and set mode to Analog