I'm developing a unity application for android that needs to measure device movement with the help of accelerometer. The problem is that these values contains the gravity. Some say in order to remove the gravity I have to convert the acceleration to global acceleration and then just remove the gravity from Z axis, but I do not know how to do it? Is there any special unity function to do this?
Thanks
This thread on Unity forum clear things up :
As "inkredibl" from Unity Technologies says:
In Unity
Gyroscope.rotationRate
is the real gyroscope data, all the other properties of that class use other sensors (when available) to come up with better estimations of real-world device movements.Gyroscope.gravity
andGyroscope.userAcceleration
are related to accelerometer but with the help of other sensors they have gravity separated out from device acceleration to make it easier for developers to use (but this is again an estimation, they're not perfect, only close enough).
So Gyroscope.userAcceleration
is the answer of this question.
Input.acceleration is accelerometer data and it's measured in multiples of g (Eearth's gravity), that's why it's magnitude is 1 when the device is not being moved. Try logging it when the device is thrown up in the air and it should be close to zero (that's because the device is in free-fall at that moment). Compass.rawVector is magnetometer data and again all the other properties of that class are derived using various sensors not just the magnetometer.