Having hard time working with rotations and gyro

Hi,

I need some help with rotations and quaternions:

I’m reading the Gyroscope of my mobile phone and the results I’m getting are not consistent with what is supposed to.

The X axis of Input.gyro.attitude is working good, I use Input.gyro.attitude.eulerAngles.x and 0 degrees is the north no matter how tilted the phone is.
The problem is with the Y axis, that is supposed to be the tilt degrees, it varies the value if I move the X axis while keeping the same tilt.

I have been busy at this for days now and cannot find an explanation for this behavior.

Try this:

I used some examples of reply and unity to made this code, and him works fine to me:

float yRotation;
float xRotation;
void Start{

Input.gyro.enabled = true;
}
void Update{
yRotation += -Input.gyro.rotationRateUnbiased.y;
xRotation += -Input.gyro.rotationRateUnbiased.x;

transform.eulerAngles = new Vector3(xRotation, yRotation, 0);
}

It’s an old thread however if someone bumps on this one, the following thread helped me out a lot:
http://forum.unity3d.com/threads/gyroscope-quaternion-to-unity-camera-help-please.75288/

These simple commands made the tricks for me (unless the phone is flipped):

`
Camera.mainCamera.transform.rotation = gyroQuaternion;

Vector3 ea = gyroQuaternion.eulerAngles;

Camera.mainCamera.transform.eulerAngles = new Vector3( -ea[0], -ea[1], ea[2]);
`

This is because it is the EulerAngles representation of the rotation Quaternion which does not obey a normal degree rotation and will not always be what you expect even though they are correct for the rotation. I suggest you read a little up on Quaternions and how they work.

As a test: Have you tried rotating an object in your scene to match the rotation of the gyroscope, just to see if the rotation is correct? Example: transform.rotation = Input.gyro.attitute;