Some Android devices have a gyroscope sensor that provides information about the rate of rotation in rad/s around a device’s x, y, and z axis.

    NOTE: The gyroscope is currently not available on iOS devices since there is no implementation in the RoboVM - backend yet.

    You must first enable the gyroscope in your android config. (Typically in your AndroidLauncher.java file)

    1. config = new AndroidApplicationConfiguration();
    2. config.useGyroscope = true; //default is false
    3. //you may want to switch off sensors that are on by default if they are no longer needed.
    4. config.useAccelerometer = false;
    5. config.useCompass = false;

    Querying whether the gyroscope is available works as follows:

    1. boolean gyroscopeAvail = Gdx.input.isPeripheralAvailable(Peripheral.Gyroscope);

    Once you determined that the gyroscope is indeed available, you can poll its state:

    1. if(gyroscopeAvail){
    2. float gyroX = Gdx.input.getGyroscopeX();
    3. float gyroY = Gdx.input.getGyroscopeY();
    4. float gyroZ = Gdx.input.getGyroscopeZ();
    5. }