- Home /
Accelerometer z axis problem
hi , I'm trying to build a project which uses accelerometer as its input . I created a guitext to debug and see how my Nexus S accelerometer works . I wrote this :
function Update()
{
var phoneX = Input.acceleration.x ;
var phoneY = Input.acceleration.y ;
var phoneZ = Input.acceleration.z ;
guiText.text = "phoneX : " + phoneX +
"\nphoneY : " + phoneY +
"\nphoneZ : " + phoneZ;
}
I'm trying to use the z value of accelerometer . I think the axis are y is in direction of phone's height , x in direction of phone's width and z is the vector coming out of screen . but holding the phone parallel to the floor and rotating it around it's z doesn't affect any of the accelerometer's values.
I'll be appreciated if someone can help me with this
thanks
Answer by aldonaletto · Aug 08, 2012 at 12:45 AM
That's right. The only acceleration constantly acting over the accelerometer is the gravity. With the phone parallel to the floor, the whole gravity is applied opposite to the Z axis direction, thus it should show a value -1 (-1 G) while the other axes should be 0. Slowly rotating it to the upright position will move gravity from Z to the Y axis, and you should get Y = -1 and Z,X = 0 when completely vertical.
Maybe you're confusing accelerometer with gyroscope - a gyroscope can track rotations, while the accelerometer only reports the result of forces acting on the phone - usually fast movements (shaking, hitting, etc.)
thanks so much Aldo . the problem I'm facing now is that it seems gyro doesn't work with Android devices and Input.gyro.enabled seems to be always false . I tried to change the gravity with Physics.gravity = Vector3(0,0,1) but it seems that accelerometer works with real gravity not the scene gravity . I'll be appreciated if you've some other idea to make it work . thanks so much
Yes, the accelerometer axes are fixed, and Physics.gravity isn't taken into account. About the gyro, this thread ( http://forum.unity3d.com/threads/118786-android-gyroscope-in-unity-3.5-beta ) shows that other people are having problems with Android gyro in Unity - maybe it's not correctly implemented in Unity 3.5 versions yet. Have you tried to set Input.gyro.enabled to true? It seems that it's false by default in Android devices.
thanks Aldo . yes I've tried to set to true but it seems to be always false . there's GyroDroid in asset store , I haven't tested it http://forum.unity3d.com/threads/101279-GyroDroid-2.0-Access-each-and-every-sensor-on-Android-devices-RELASED . thanks again Aldo
Your answer
![](https://koobas.hobune.stream/wayback/20220613075331im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to find Accelerometer delta value? 1 Answer
3D: how to avoid jerks in a character movement using accelerometer 1 Answer
roll ball in two axis using devices accelerometer. 1 Answer
How do I rotate my player and still make it go where I tilt my phone? 1 Answer
Is it possible to get the forward and backward movement of android device 1 Answer