How to implement input from device accelerometer and gyroscope?

I’m trying to get real-time input from the device accelerometer and gyroscope but couldn’t find any information in the docs.

How can I use input from these sensors in order, for instance, to control the movement of a character through the scene? Shake the phone and use that as a trigger to something in the scene? Control the camera with the device rotation? Etc, these are just some examples of the types of input I’m looking for when trying to use these sensors as input.

Any ideas/suggestions on how to implement this type of thing?

The good thing about Babylon.js being OSS is that you can look at the source to see how to do something, if only you know where to look :slightly_smiling_face:

Check out the code for the DeviceOrientationCamera - that will probably show you exactly what you’re looking to do!

1 Like

So, does that mean that there’s no abstraction/implementation that allows to use these sensors as input on babylon?

Aside from the device orientation web browser API’s , that is correct; the DeviceOrientationCamera has a Class that wraps the browser events, but that is specific logic related to camera management.

There is active work going on in this area of Babylon.js as well as similarly-framed feature requests that echo your sentiments


Thank you guys for the suggestions! I’ll save the links.
I think these aren’t really what I’m looking for, though.
If there isn’t any implementation of this, I might just start by trying to implement the default browser javascript sensors API. At least for that there are tons of resources and documentation, instead of digging through Babylon’s source code.
Thank you!

1 Like