Search Unity

Joystick axes - delta input and 3Dconnexion

Discussion in 'Scripting' started by andre-ivankio, Apr 5, 2010.

  1. andre-ivankio

    andre-ivankio

    Joined:
    Mar 29, 2010
    Posts:
    53
    How to properly get the delta input from the 6 joystick axes?

    I am trying at least to implement the space navigator in the runtime camera. It works, but I need help with the absolute values of axes input.

    Because of the absolute axis, I had to do that oldVector dirty workaround. One problem is that it would be even dirtier to implement the filtering off of small inputs.

    Another problem is that it will stop working whenever I go beyond 1 or -1 on any axis. I needed to set sensitivity very low, but it will still reach a cap.

    I believe I'm overlooking some basic Unity functionalities, am I? I've seen some hints about mouse delta input, but I couldn't find it how to set for this case.

    Code (csharp):
    1.  
    2. // INPUTS:
    3. //
    4. // joyX = X axis
    5. // joyY = 3rd axis * invert
    6. // joyZ = Y axis * invert
    7. // tilt = 6th axis
    8. // pan = 4th axis * invert
    9. // roll = 5th axis
    10. //
    11. // all sensitivity set to 0,001
    12.  
    13. var translateSpeed = 100.0;
    14. var rotateSpeed = 100.0;
    15.  
    16. private var joyTrans = Vector3(0,0,0);
    17. private var joyRotate = Vector3(0,0,0);
    18.  
    19. private var joyOldTrans = Vector3(0,0,0);
    20. private var joyOldRotate = Vector3(0,0,0);
    21.  
    22. private var texto = "monitor";
    23.  
    24. //@script AddComponentMenu("Camera-Control")
    25.  
    26. function OnGUI () {
    27.    texto = joyTrans.ToString();
    28.    GUI.Box (Rect (10,10,200,20), texto);
    29.    texto = joyRotate.ToString();
    30.    GUI.Box (Rect (10,30,200,20), texto);
    31.    }
    32.  
    33. function Start () {
    34.    joyTrans.x = Input.GetAxis("joyX");
    35.    joyTrans.y = Input.GetAxis("joyY");
    36.    joyTrans.z = Input.GetAxis("joyZ");
    37.    joyOldTrans = joyTrans;
    38.    
    39.    joyRotate.x = Input.GetAxis("pan");
    40.    joyRotate.y = Input.GetAxis("tilt");
    41.    joyRotate.z = Input.GetAxis("roll");
    42.    joyOldRotate = joyRotate;
    43. }
    44.  
    45. function LateUpdate () {
    46.  
    47.       joyOldTrans = joyTrans;
    48.       joyTrans.x = Input.GetAxis("joyX");
    49.       joyTrans.y = Input.GetAxis("joyY");
    50.       joyTrans.z = Input.GetAxis("joyZ");
    51.      
    52.       joyOldRotate = joyRotate;
    53.       joyRotate.x = Input.GetAxis("pan");
    54.       joyRotate.y = Input.GetAxis("tilt");
    55.       joyRotate.z = Input.GetAxis("roll");
    56.      
    57.       var position = (joyTrans-joyOldTrans) ;
    58.       var rotation = (joyRotate-joyOldRotate);
    59.       position *= 1*translateSpeed;
    60.       rotation *= 36*rotateSpeed;
    61.        
    62.       transform.Translate (position);
    63.       transform.Rotate (rotation);
    64. }

    I also guessed that the call bellow should reset the all axes to 0, but it did not when I put it on the start function.
    Code (csharp):
    1. Input.ResetInputAxes();