Search code examples
javascriptaframedevice-orientation

A-Frame look-controls very unstable on older devices


I'm building a 360 panorama viewer with A-Frame 1.0.4 and I'm having some trouble with older devices that I don't know how to solve. I'm testing in a WebView inside an Android application.

On most recent devices, the gyroscope and accelerometer work great, but on older devices (for example ASUS X008D), it's all shaky, the view can't stay still when I put the phone on the table or when I hold it. I thought it could be due to polyfills but I can't figure how. I added some logs to check for DeviceMotionEvent and DeviceOrientationEvent and both are recognized but it seems like it's not enough.

How could I be sure that the events are handled correctly and eventually disable the hmd in look-controls manually when it's not stable enough? There would still be the dragging and I would be fine with that.

Thanks for your help :)


Solution

  • After further investigations I found out where the issue came from. It was because the Sensor API was not available on some devices and the Gyroscope wasn't read correctly. If I understood correctly there was a fallback on DeviceMotion but it was probably not good on older devices, I don't know...

    What I did to "fix" this was writing this little snippet to check that the Gyroscope class was available. If it was not I disabled all movements from look-controls component to allow only manual movements. I hope it can help anyone who meets this issue. It's kinda quick'n'dirty but it did the job so I'm okay with this.

    var gyroscope = null;
    try {
        gyroscope = new Gyroscope();
        gyroscope.addEventListener('error', event => {
            document.getElementById("camera").setAttribute("look-controls", "magicWindowTrackingEnabled: false");
        });
        gyroscope.start();
        // Stop the gyroscope after trying so it does not run in background.
        setTimeout(function() { gyroscope.stop(); }, 500);
    } catch (error) {
        document.getElementById("camera").setAttribute("look-controls", "magicWindowTrackingEnabled: false");
    }
    

    There's also an open issue about it on A-Frame github page.