I'm working on an android game, where the player's movement (left,top,right,bottom) is calculated depending on what direction you tilt your device.
I also wanted to do that at the beginning of the game, it calculates the current tilt, so that if the player is holding the phone in any position, he can still play the game.
Here is how I have done it:
(on start):
defaultAccelX = SceneManager.activity.getAccelX();
defaultAccelY = SceneManager.activity.getAccelY();
(and then on every update):
float modifiedAccelX = (SceneManager.activity.getAccelX() - defaultAccelX);
float modifiedAccelY = (SceneManager.activity.getAccelY() - defaultAccelY);
Now this works if the player keeps the phone towards the bottom. But if I hold the phone upside down, top and bottom are reversed, and right doesn't work.
Would anyone know how should I handle it to work in any direction ?
Thank you