Tilt and Gravity controls on Android sensitivity

Hi Bergwen,

I don’t know if you have exactly the same problem as I had, but the high sensitivity of the tilt values on Android devices is the result of wrong axis values (at least in my case).

While I was building a roller game on my Nexus 7 I noticed that if the screen was facing up, the X and Y tilt values wrapped from -3.14(…) to +3.14(…). If the screen was facing down, the axies behaved as they should. So I made myself a little function that recalculates the axis values on android devices, so that (0,0) is facing up, not down:

Now my tilting works as expected. The resulting values can be multiplied by another float to control the sensitivity. The clamp at the end of the function is optional.

I hope that this helps you.