- Home /
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
Answer by kieblera5 · Jul 07, 2011 at 03:15 PM
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.
Your answer
Follow this Question
Related Questions
how to convert Input.mousePosition into iphone/android accelerometer? 1 Answer
Issues with accelerometer calibration? 1 Answer
Match the tilted angle of phone to object. 0 Answers
Mapping accelerometer to Camera's position 2 Answers
Accelerometer - accounting for gravity for arbitrary device angle 1 Answer