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

Axis Input "Dead" problematic for diagonal input

Discussion in 'Scripting' started by Marrt, Apr 23, 2016.

  1. Marrt

    Marrt

    Joined:
    Feb 7, 2012
    Posts:
    612
    Just wanted to point out that when using the Input Manager and setting "Dead" (the portion where Joystick Movements are ignored) creates problems.

    Example Analog Stick:

    When setting Dead to "0.0" you get the raw values - good
    When setting Dead to "0.5" you get a new scale from 0 to 1 STARTING with 0.0 where previously 0.5 was

    Why is this a problem? Diagonal movement magnitude is reduced by Dead:
    - if your Diagonal Vector consisted out of Vector2(0.707,0.707), it will now read: Vector2(0.414,0.414)
    - a magnitude of 1 will become 0.58 if Dead is at 0.5
    - Dead higher 0.0 will always decrease your diagonal input magnitude


    this is why (geometry):
    upload_2016-4-23_2-57-14.png

    these are also the readings i get when i set one axis at Dead:0.5 and the other at Dead:0.0
    (somehow one analog stick of mine affects both "y axis" and "axis 5" for x-movement, making this test easy)
    upload_2016-4-23_2-56-49.png


    Verdict: Always clamp the analog-stick-magnitude yourself and leave Dead on 0.0
    Fix for UnityDevs: offer Flag "startFromDead": don't rescale the axis from the dead-value, just start with the Dead value and Clamp every input below Dead to zero.

    This is how i do it to have homogenous magnitudes in all directions and Dead:
    Code (csharp):
    1. //GAMEPAD
    2. moveDir = new Vector3(Input.GetAxis("x axis"), 0F, Input.GetAxis("y axis"));
    3.  
    4. //Clamping and Dead
    5. float moveDirMag = moveDir.magnitude;
    6. float axisDead = 0.2F;  
    7. if(moveDirMag    < axisDead){
    8.     moveDir = Vector3.zero;
    9. }else{
    10.     moveDir = moveDir.normalized *Mathf.Clamp(moveDirMag, axisDead, 1F);
    11. //  moveDir = moveDir.normalized *Mathf.InverseLerp(axisDead, 1F, moveDirMag);//if you want to start at 0F magnitude, untested
    12. }
    If you need to start the magnitude at 0F rather than with axisDead, you need to rescale the value according to your new-axis-min (=axisDead) and 1F. I didn't test it, but inverse lerp on magnitude should achieve this
     
    Last edited: Aug 17, 2016
    Martin_H likes this.