The device accelerometer reports values for each axis in units of g-force. i.e. (x,y,z) triplets.
Each value, is in the range -1.0f to 1.0f;
I'm making a game with simple tilt controls, so that if you tilt left, the character goes left, and if you tilt right, then the character goes right.
Based on the accelerometer values, if the smartphone was held vertically upright, then the Y value seems very close to 1, The Z value is very close to 0, and the X value ranges from -1.0 to 1.0f depending on if you are tilting the phone 90 degrees to the left or right. In this case, it is easy to figure out the intended direction the user wants the character to move since we can just read the X value.
But what about the case where the phone isn't held perfectly upright? How should I detect the direction the player wants to go?
- I'm assuming I should do some kind of scaling factor, since 0 to 1 implies how upright the device is, I can apply a scaling factor to the x coordinate. Does that make sense ?
Am I right in assuming that if the phone is face down, then it is not possible to determine the intended direction simply through accelerometer values ?