[XDK/JS] Calculating tilting delta

I’m preparing to make top-down game controlled with a gyroscope (by tilting your phone). I’m using following code to get data of device’s tilt:

[code]var xtilt = runtimeScene.getVariables().get(“xtilt”);
var ztilt = runtimeScene.getVariables().get(“ztilt”);

if (window.DeviceOrientationEvent) {
window.addEventListener(‘deviceorientation’, function(e) {

Which works great, except it gives absolute value of tilt (in degrees, I think). Have no idea how to calculate “delta” value (how much device was tilted).

Maybe ask at the start of the game “Please put your device on a flat table” (or something like that) and record the values in two global variables? :slight_smile: