x


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

more ▼

asked Aug 07 '12 at 09:25 PM

smtabatabaie gravatar image

smtabatabaie
60 14 14 17

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.)

more ▼

answered Aug 08 '12 at 12:45 AM

aldonaletto gravatar image

aldonaletto
41.5k 16 42 197

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

Aug 08 '12 at 02:20 AM smtabatabaie

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.

Aug 08 '12 at 12:18 PM aldonaletto

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

Aug 08 '12 at 02:54 PM smtabatabaie
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2481
x322
x140

asked: Aug 07 '12 at 09:25 PM

Seen: 1061 times

Last Updated: Aug 08 '12 at 02:54 PM