Accelerometer vibration, How to smooth?

That’s my question:

I have the accelerometer controling the rotation of a table, it’s working fine but it’s vibrating a lot, how can i smooth that vibration, like passing some filter to the accelerometer information.

Thanks :slight_smile:

Edit1:

I found the lowpass filter inside the documentation, but i don’t understand very well how to implement this in a js script, someone can point me in the right direction please? :slight_smile:

Instead of setting the rotation to the accelerometer rotation, try Vector3.Lerp to smoothly move to the desired rotation.

I ran into the same problem, here’s how I smoothed mine out

// rotation multiplier for the accelerometer 
// (rotating the iPhone 90 degrees will give this rotation)
var maxTilt : float = 65.0;

// set this lower to smooth it out more, but then 
// the rotation is slower
var rotationDamp : float = 5.0;

// rotation of the table
var currentRotation : float = transform.eulerAngles.z;

// rotation of the accelerometer
var wantedRotation : float = iPhoneInput.acceleration.normalized.y * maxTilt * -1;

// rotation value is smoothed out with the LerpAngle
z = Mathf.LerpAngle(currentRotation, wantedRotation, rotationDamp * Time.deltaTime);

Your way is really great dbokser, the rotation is so smooth, but when the ipod/iphone is stopped the sensor is still vibrating, is there some way to implement the low pass filter to avoid this? (or any other technique)

Thanks for your answer :smile: