- Home /
Using a VR controller as a joystick
I'm trying to use a 3dof controller as a a joystick but I'm having trouble with the math that involves. I've been trying to create an inverse rotation by aiming the controller up and setting a a value based on the rotation of the controller, and then taking the new rotation from the controller to create an inverse rotation relative to the static value I set from aiming the controller upwards.
Problem is that if the rotation is even slightly rotated (instead of eulers of 0,90,0 being straight up the value I could retrieve would be 15,90,0) the rotation will be a bit erratic rotating when I tilt the controller in even the slightest incorrect rotation.
Essentially I just want to be able to create a local rotation from an upwards facing controller to consistently get X and Z rotations of the controller to rotate it like a flight stick, I just think I'm missing something.
Code I'm using so far:
localControllerRotation = InputTracking.GetLocalRotation(XRNode.RightHand);
if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger) > 0.1f)
{
setRot = localControllerRotation;
}
Vector3 inv = (Quaternion.Inverse(localControllerRotation) * setRot).eulerAngles;
gameObject.transform.localEulerAngles = new Vector3(inv.x, 0, -inv.y);
Any help would be great, thanks