- Home /
Input.accelerometer x,y,z always returning zero
Hi, I am creating a simple game to achieve first person control on my android device HTC one M8. I started with joystick and could successfully move in FP. I tried in many ways with accelerometer but it seems Input.accelerometer x,y,z are always zero. I tried it on couple of other android devices but in vain. Player is in center of a room where camera is child of player. Fps is a component of player.
I am new to Unity, am I missing to add something as I could see unity games on my own device with First person control. I am using unity 4.6.2. Any help on this topic will be highly appreciated.
Here is the code I am trying, player is moving back
function Update() {
var dir : Vector3 = Vector3.zero; dir.x = Input.acceleration.x; dir.z = Input.acceleration.z; if (dir.sqrMagnitude > 1) dir.Normalize(); dir *= Time.deltaTime;
if(Input.acceleration.x != 0){
thisTransform.Translate (dir.x, dir.z, 0);
}else{
dir.x = -0.01f;
thisTransform.Translate (dir);
}
}
have you set the sensitivity in edit > project settings > input? otherwise this should do the trick. float dirX = Input.acceleration.x; float dirZ = Input.acceleration.z; transform.Translate (dirX, dirZ, 0);
Thanks for the reply. I checked the sensitivity and code I am using is similar to the suggested code. Player is moving back suggesting that acceleration values are zero.
do you have onscreen feedback of the accelorometer ? and its smart to clamp the player. maybe it moving extremely fast.
I didn't add any onscreen feedback for now but I tested in many ways all leading to same conclusion that the values are zero. I will learn and create onscreen feedback and get back to you.
just fill a gui or a mesh text with the accelorometer values. http://docs.unity3d.com/ScriptReference/Text$$anonymous$$esh.html
Answer by smoggach · Feb 06, 2015 at 04:07 PM
Go to edit->project settings->player and make sure that Accelerometer Frequency in the Other Settings section isn't set to "disabled".
unfortunately accelerometer frequency is not an option in player settings when building for Android. I already checked for it in Unity 4.6.2 which I am using.
Then chances are you'll have to do something to your manifest file in order to activate the accelerometer. Any android developers know the answeR?
As far as my experience in Android is concerned, adding accelerometer in manifest is not a necessity unless we intend to publish to app store which is used for filtering devices. Usually sensory hardware is accessed by registering a listener if it exists which is identified using sensor manager. I don't think this is the problem.
i dont think its a manifest problem. you can simpely check if it is by removing it.
I was developing on Android, and using Cloudbuild to build for iOS. This setting is invisible in my editor, but you can go into ProjectSettings>ProjectSettings.asset and find accelerometerFrequency: 0 and set it to 30 or 60
Your answer
![](https://koobas.hobune.stream/wayback/20220613182631im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Sensor Fusion of Accelerometer and Gyroscope 0 Answers
(Android) TouchScreenKeyboard isn't showed up when i clicked InputField in Unity 4.6.1p2 1 Answer
Runtime terrain loading, Partial terrain loding 1 Answer
How do I access CoreMotion and the Android equivalent? 0 Answers
Can you get the height that you are holding the phone? 2 Answers