When I tilt my mobile phone rapidly to left or right to move the player in my app, the player starts wiggling for a short time. How can I remove this effect and make it as smooth as it is e.g. in Doodle Jump? I'm using the raw accelerometer sensor event values to add to the player coordinates. Is there any algorithm or should I just use the sensor differently?
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() != SENSOR)
return;
if(this.isRunning()) {
spieler.setMoveSpeed(-event.values[0]);
}
}
you need to use a low pass filter , which is specifically designed for the problem you are facing. it will smooth out the accelerometer values
Example code:
float rawX = event.values[0];
float rawY = event.values[1];
float rawZ = event.values[2];
// Apply low-pass filter
mGravity[0] = lowPass(rawX, mGravity[0]);
mGravity[1] = lowPass(rawY, mGravity[1]);
mGravity[2] = lowPass(rawZ, mGravity[2]);
for more information on low pass filter check out http://developer.android.com/reference/android/hardware/SensorEvent.html