I'm using the gyroscope events in CoronaCards to create a tilt game that requires the user to keep a creature balanced on a rope. However, the gyroscope drift is horrendous and very quickly winds up being off by upwards of 45 degrees, especially if you rotate the device around a non-Z axis.
Here is the snippet that handles the tilting:
local degreesDelta = (radiansDelta * (180/math.pi) ) * -1 -- clamp to 1 decimal place to try and mitigate some of the drift local clamped = math.round(degreesDelta*10)*0.1 -- deltaOutput.text = string.format("clamped delta: %.1f", clamped) local currentRotation = self.tiltLine.rotation local newRotation = currentRotation + clamped self.tiltLine.rotation = newRotation
This moves a line that should always point straight upwards, so we know how far the device is tilted and use it to control the balance of a creature.
This works for a very short time, but it very quickly drifts to a point where it no longer points upwards and can drift as far as 45 degrees off or more.
I would like to use the accelerometer to either augment these results or perhaps implement a kalman filter to mitigate the drift, but the accelerometer is broken in CoronaCards and cannot be used to receive events, so the alternative is to excise this out of Lua and do the sensor receiving in native iOS which is not ideal.