- Home /
accelerometer not working
Hi,
why is the cube moving when I use a controller, but not with the accelerometer?
void Update () {
text.text = "X: " + Input.acceleration.x + "; Z: " + Input.acceleration.z;
//transform.position = new Vector3(10* Input.acceleration.y, 0, 10* Input.acceleration.z);
transform.Translate(Input.acceleration.x, 0, Input.acceleration.z);
//transform.position = new Vector3(10* Input.GetAxis("Horizontal"), 0, 10* Input.GetAxis("Vertical"));
transform.Translate(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
}
(I'm on a Xperia Z3 compact by the way)
Try adding a Debug.Log("X accel : " + Input.acceleration.x + " Y : accel" + Input.acceleration.z)
at the end of the block as it should return a maximum of one so the actual number will be smaller like 0.2 or something
Try multiplaying the accerlation by 20 and see if it moves if not try 100 if it still dosent work then i am not too sure.
Well, I know that the Gyro is actually disabled by default and needs to be enabled first before use(Input.Gyro.enabled = true), it wouldn't surprise me if you had to have it enabled for Input.acceleration to work too, even though it's not in the Gyro class for some reason. (http://docs.unity3d.com/ScriptReference/Gyroscope-enabled.html)
I'm not sure if this is the case or not, and don't have the ability to set up a test project for my phone at the moment, but you might want to give it a shot and tell us how it went.
@$$anonymous$$, @Runalotski , im having the same problem with my xperia z3 compact. It was working fine the night before, but this morning, the phone decided the screen would not auto rotate. Ive gone into the normal settings and switched auto rotate on and off several times, ive restarted the phone, and just did a factory reset,ive ran the diagnostic tests too. but nothing. Ive now investigated deeper and found that by typing ##7378423## into the keypad, it gets me into some settings i didnt know existed.
Gyroscope is working, but the accelerometer is not.
these are the readings i get from the settings:
X: -38.0792 Y: -38.9015 Z: 39.2839
I have no idea what they are supposed to be, i assume these readings are off and they should be something else.
I really dont know much about coding on an android and have not dared to do anything involving the Root thing.
Any help would be appreciated to fix this. i cant even take pictures because they appear upside down or sideways, even if the camera button is facing the right way up?
Look forward to receiving any help possible..
Val,@$$anonymous$$, @Runalotski , im having the same problem with my xperia z3 compact. It was working fine the night before, but this morning, the phone decided the screen would not auto rotate. Ive gone into the normal settings and switched auto rotate on and off several times, ive restarted the phone, and just did a factory reset,ive ran the diagnostic tests too. but nothing. Ive now investigated deeper and found that by typing ##7378423## into the keypad, it gets me into some settings i didnt know existed.
Gyroscope is working, but the accelerometer is not.
these are the readings i get from the settings:
X: -38.0792 Y: -38.9015 Z: 39.2839
I have no idea what they are supposed to be, i assume these readings are off and they should be something else.
I really dont know much about coding on an android and have not dared to do anything involving the Root thing.
Any help would be appreciated to fix this. i cant even take pictures because they appear upside down or sideways, even if the camera button is facing the right way up?
Look forward to receiving any help possible..
Val