Calabrate Accelerometer

Hi

Im using this code to rotate and object in my scene.

function Update () {
iphoney=Input.acceleration.z;
transform.Rotate(Vector3.forward*iphoney*10.0); 

if (transform.eulerAngles.z <= 10){
transform.eulerAngles.z = 10;
}
if (transform.eulerAngles.z >= 75){
transform.eulerAngles.z = 75;

}

}

I need to calibrate the accelerometer to make game play more comfortable. At the moment I have to have the phone flat which is uncomfortable. I would prefer the phone to sit at about 45 degrees. The project will be landscape orientation.

Any help will be appreciated.
Thanks

Make a calibration button. Save the Input.acceleration and subtract or add the result from the iphoney variable when you initialize it.

Something like this:

//when calibrating
globals.calibrationLevel=Input.acceleration.z;

//when initializing
iphoney=Input.acceleration.z-globals.calibrationLevel;

I’m not remembering if you add or subtract the two numbers. I’m unable to test at the moment.