Reading device rotation around X axis

(Wrote an incorrect title btw…)

I’ve been trying to read the rotation around the Y axis using the same method as Unity’s TiltControls in the standard assets which reads from the accelerometer. This seems to only work for the X and Z axis though.

case AxisOptions.ForwardAxis:
    angle = Mathf.Atan2(Input.acceleration.x, -Input.acceleration.y)*Mathf.Rad2Deg + centreAngleOffset;
    break;
case AxisOptions.SidewaysAxis:
    angle = Mathf.Atan2(Input.acceleration.z, -Input.acceleration.y)*Mathf.Rad2Deg + centreAngleOffset;
    break;

Does anybody know how to apply this same technique to read from the Y axis? I feel like I’ve just been confusing myself and the answer is right in front of me…

To get the pitch/roll you can use these equations:

Roll = Mathf.Atan2(Y, Z) * 180/Mathf.PI;
Pitch = Mathf.Atan2(-X, Mathf.Sqrt(Y*Y + Z*Z)) * 180/Mathf.PI;

In your diagram roll would be X axis and pitch would be Y axis. You can’t get the Z axis because the accelerometers don’t give you enough information to calculate it. (i.e. you can spin your iphone on the desk and the accelerometer values won’t change)