@EasyDev
Here's what I do in a game of mine: in my case, the player slides back and forth along the bottom of the screen. This makes use of the low-pass filter as well as a player jitter adjustment I added for when the sensitivity is set higher, and an accelerometer jitter factor too.
I have these defined:
float accelJitter = 0.01;
float playerJitter = 1.0;
const float kFilteringFactor = 0.1;
UIAccelerationValue rollingY;
//this would the tick method
-(void) update: (ccTime) dt {
[self setPosition:self.lastPosition];
}
- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration {
BOOL shouldMove = NO;
rollingY = ((acceleration.y * kFilteringFactor) + (rollingY * (1.0 - kFilteringFactor)));
float accelY = acceleration.y - rollingY;
float newX = self.position.x + (sensitivity *-accelY);
if (accelY < -accelJitter || accelY > accelJitter) shouldMove = YES;
if (shouldMove) {
if (newX < playerMaxLeft-playerWidth/2) {
newX = playerMaxLeft-playerWidth/2;
}
if (newX > playerMaxRight-playerWidth/2) {
newX = playerMaxRight-playerWidth/2;
}
if (((newX - self.position.x) > playerJitter) ||
((self.position.x - newX) > playerJitter)) {
[self setLastPosition:CGPointMake(newX, self.position.y)];
}
}
}