Search code examples
c#androidunity-game-enginerotationaccelerometer

How Convert Device Acceleration to Global Acceleration


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


Solution

  • This thread on Unity forum clear things up :

    https://forum.unity.com/threads/unity-and-the-accelerometer-vs-the-gyroscope-a-complete-guide.451496/

    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 and Gyroscope.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.