x


3dconnexion - Delta joystick input

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.

// INPUTS:
//
// joyX = X axis
// joyY = 3rd axis * invert
// joyZ = Y axis * invert
// tilt = 6th axis
// pan = 4th axis * invert
// roll = 5th axis
//
// all sensitivity set to 0,001

var translateSpeed = 100.0;
var rotateSpeed = 100.0;

private var joyTrans = Vector3(0,0,0);
private var joyRotate = Vector3(0,0,0);

private var joyOldTrans = Vector3(0,0,0);
private var joyOldRotate = Vector3(0,0,0);

private var texto = "monitor";

//@script AddComponentMenu("Camera-Control")

function OnGUI () {
   texto = joyTrans.ToString();
   GUI.Box (Rect (10,10,200,20), texto);
   texto = joyRotate.ToString();
   GUI.Box (Rect (10,30,200,20), texto);
   }

function Start () {
   joyTrans.x = Input.GetAxis("joyX");
   joyTrans.y = Input.GetAxis("joyY");
   joyTrans.z = Input.GetAxis("joyZ");
   joyOldTrans = joyTrans;

   joyRotate.x = Input.GetAxis("pan");
   joyRotate.y = Input.GetAxis("tilt");
   joyRotate.z = Input.GetAxis("roll");
   joyOldRotate = joyRotate;
}

function LateUpdate () {

      joyOldTrans = joyTrans;
      joyTrans.x = Input.GetAxis("joyX");
      joyTrans.y = Input.GetAxis("joyY");
      joyTrans.z = Input.GetAxis("joyZ");

      joyOldRotate = joyRotate;
      joyRotate.x = Input.GetAxis("pan");
      joyRotate.y = Input.GetAxis("tilt");
      joyRotate.z = Input.GetAxis("roll");

      var position = (joyTrans-joyOldTrans) ;
      var rotation = (joyRotate-joyOldRotate);
      position *= 1*translateSpeed;
      rotation *= 36*rotateSpeed;

      transform.Translate (position);
      transform.Rotate (rotation);
}

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.

Input.ResetInputAxes();
more ▼

asked Apr 06, 2010 at 12:11 AM

andre.ivankio gravatar image

andre.ivankio
22 3 2 3

Not quite sure I follow. What exactly "will stop working whenever [you] go beyond 1 or -1 on any axis"? How/where do you even go beyond 1 or -1? What do you mean by "absolute Value"? Input.GetAxis for Joysticks (per the docs) returns a smoothed value indicating current state. Input. Input.GetAxisRaw will return non-smoothed values.

Sep 24, 2010 at 07:21 PM skovacs1

Have you tried setting the position and rotation rather than calculating a translation (transform.position = joyTrans * translateSpeed;transform.eulerAngles = joyRotate * rotateSpeed;) to visualize how your axes are positioned? This should accomplish the same as your translation/rotation etc.

Sep 24, 2010 at 07:22 PM skovacs1

The docs say "Note also that the Input flags are not reset until "Update()", so its suggested you make all the Input Calls in the Update Loop." Perhaps because you put the call in Start(), it did not perform as you expected? ResetInputAxes will set the axes to 0 for one frame only and, with the code above, the object would translate to mimic the position of the joystick as the code would have it do normally as the delta from 0 to the current position will be the current position.

Sep 24, 2010 at 07:27 PM skovacs1

What joystick are you using, then if we have the same joystick we can compare results and pin point the problem. I for example have a logitech gamepad with 6 axis and all is working fine on all axis.

Nov 12, 2010 at 06:54 AM Jean Fabre

Have you solved your problem? I am facing the same problem...

Jan 31, 2012 at 01:25 PM ilexius
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x9083
x2733
x1568

asked: Apr 06, 2010 at 12:11 AM

Seen: 2896 times

Last Updated: Jan 31, 2012 at 01:25 PM