So I have done a basic calibration in my game like so: Calibrate Code:
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
[[NSUserDefaults standardUserDefaults] setFloat:acceleration.x forKey:@"X-Calibrate"];
}
Then in my game view these are some defines for the accelerometer:
#define kFilteringFactor 0.13
#define MAXXACCELERATION 24
In the init method of my game class I do this:
calibrationFloat = [[NSUserDefaults standardUserDefaults] floatForKey:@"X-Calibrate"];
Then I do this:
- (void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
//Low Pass Filter (gets rid of little jitters) + Calibration value combined
rollingX = ((acceleration.x - calibrationFloat) * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor));
}
calibrationFloat is set to the value read from NSUserDefaults before the game starts.
Then in the game loop I do this:
int rollingAmount = (IS_IPAD() ? 52 : 44);
CGFloat xFloat = (rollingX * rollingAmount);
pos.x += xFloat < -MAXXACCELERATION ? -MAXXACCELERATION : (xFloat > MAXXACCELERATION ? MAXXACCELERATION : xFloat);
Then I set the position of my image based upon pos.x. This however is the problem: After I calibrate, the sensitivity of the movement of my image because very high making it very fast movements. Before I calibrate, the movement is at a nice pace so something with the calibration must be going wrong.
Does anything not seem right here, am I doing something wrong with the calculations?
Thanks!