2

I am trying to have the tilt of the Z axis in an Android phone power the movement of a Libgdx Box2D car. I already know how to make the car move on my computer, but how do I implement that into an Android? The orientation is LANDSCAPE. Thanks so much!

I know something has to do with getRotation or something.... :)

rene
  • 41,474
  • 78
  • 114
  • 152

1 Answers1

2

you can get the Accelerometer Readings like this:

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

Wiki entry for more info: https://github.com/libgdx/libgdx/wiki/Accelerometer

Then just apply a force to the body with it:

body.applyForceToCenter(<your_horizontal_accel_reading>, <vertical_if_needed_0_if_not>, true);
Daahrien
  • 10,190
  • 6
  • 39
  • 71