How can I use the Accelerometer for detecting jump in LibGDX?

522 views Asked by At

I make an app for android. I'll use the accelerometer for detecting jump.Does someone know how that works? And which value will change and with how much?

1

There are 1 answers

2
Jayesh Chandrapal On BEST ANSWER

Here are some of the methods:

// Check accelerometer availability on device
boolean available = Gdx.input.isPeripheralAvailable(Peripheral.Accelerometer);

// Get current orientation
// Orientation.Landscape or Orientation.Portrait
Orientation nativeOrientation = Gdx.input.getNativeOrientation(); 

// Reading values
float accelX = Gdx.input.getAccelerometerX();
float accelY = Gdx.input.getAccelerometerY();
float accelZ = Gdx.input.getAccelerometerZ();

You will have to write your own function to combine above values and get a threshold or range of values to detect jump.

Reference: libgdx accelerometer