- Home /
Unity Accelerometer weird behavior!
Hello, everyone
(I'm using unity 4.5)
Unity accelerometer doesn't work properly, i'm trying to do the exact way provided here: http://unity3d.com/learn/tutorials/modules/beginner/platform-specific/accelerometer-input
I have set a cube like in the tutorial then i did assign the same code that is provided in tutorial to the cube, but the weird behavior is that the cube starts moving in the negative z-axis by itself without me touching the mobile, also the mobile is placed on a flat surface, in addition to that it moves insanely fast!
Note that i have tried it on two defferent devices, one is xperia z and the second is galaxy s4 but the result is the same.
any idea on what actually the problem is?
Thank you all for your time.
Please, any idea that could help is greatly appreciated.
Answer by tanoshimi · Oct 02, 2014 at 07:24 PM
Would "insanely fast" be at about 9.81 units per second, by any chance? (Put some Debug.logs in your code to print out the value of Input.acceleration.z). If so, it sounds like the accelerometer in your device is (correctly) reporting acceleration due to gravity. Some accelerometer readings are normalised to remove this, but in my experience it seems to vary from device to device.
it is between 0.998F and 1.001F
so any idea what should i do now? i mean the problem now is relative to the code or the device itself?
Thank you for your time.
i have noticed that when the mobile is not connected then the output is Zero
it seems like it is moving due to gravity on z axis but the problem is that it is working on unity z axis not the mobile z axis :\
What do you mean by "not connected"? Unity Remote won't report accelerometer readings because your PC doesn't have an accelerometer in it - you'll have to properly deploy and test on the device. But it shouldn't make a difference whether the USB cable is physically plugged in or not. What is " Unity Z axis" - you mean global z rather than local z? Perhaps a diagram would help...
Yea i'm using Unity Remote, and i mean global z. Unity gives outputs when i use Unity remote.
Unity remote might be the problem, so i will try testing on the device itself.
Thank you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613164231im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Switch axis so phone is flat with accelerometer 1 Answer
Accelerometer input working in Unity Remote, not working in build. 0 Answers
Unity 4.5 [Pro] black screen after splash in iOS 0 Answers
Bag Toss Unity Accelerometer 1 Answer
accelometer problem 0 Answers