- Home /
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();
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.
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.
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.
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.
Have you solved your problem? I am facing the same problem...
Your answer
Follow this Question
Related Questions
How to check if a key is down in editor script 2 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
customization of variables in script for in Editor? 2 Answers
[Unity Editor] Emulate Touch Input - Still Asking 12/10 1 Answer
Update - Delaying until next frame? 0 Answers