I am learning game development from the udacity course "https://classroom.udacity.com/courses/ud405/lessons/5389263706/concepts/53853441090923"

I am stuck with one statement in the code about Accelerometer. The code initialized the xAxis variable to"-Gdx.input.getAccelerometerY()" and "yAxis = Gdx.input.getAccelerometerX()"

Can anyone explain what getAccelerometerY and getAccelerometerX does actually?


1 Answer 1


The accelerometer is a thing in mobile devices that can detect when the phone is being moved. If you're on desktop or HTML, these methods always return 0. If you're on android or IOS, these methods return the acceleration on the three different axes of X, Y, and Z. (https://www.mathworks.com/help/supportpkg/android/ref/accelerometer.html explains the axes pretty well.)

For example, if you put the phone face-up on a table, getAccelerometerZ() returns -9.81 because the acceleration due to gravity on the Z axis is 9.81m/s^2 down.

  • 1
    \$\begingroup\$ Note that if you drop your phone and it's in freefall, the accelerometer will register zero (the mechanism is falling at the same rate as the phone itself). So when it's resting on a table, the acceleration it feels is the force of the table pushing UP to counter gravity (the accelerometer mechanism wants to fall down to follow gravity but the phone body is being held up so it can't follow). So, counter-intuitively, the acceleration vector you detect from gravity alone when the phone is at rest points up instead of down. \$\endgroup\$
    – DMGregory
    Jul 1, 2019 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .