Experiencing strange drift using Android Accelerometers

I’m trying to figure out how to use the phone’s tilt to control an object. So far I have a project set up with a simple cube that I want to translate around the scene using transform.Translate. Here’s my script:

	void Update () {
		Vector3 dir = Vector3.zero;

		dir.x = -Input.acceleration.x * 0.5f;

		transform.Translate (dir);
	}

I wanted to keep it simple first, testing out the x axis only. However, I find that when I set my phone down on a flat surface, the cube starts to move off the screen anyways, even when I’m not tilting the phone in any way. I have to tilt in the opposite direction to keep it steady. Why is this?

That is in my experience pretty normal actually. The accelerometers are almost never perfectly centered. For most games, this is no problem, as the player will just tilt slightly in the other direction to keep things steady, or you can implement calibration via script (tell the player to place the device on a flat surface and press a button to get an offset for your accelerometer input). Often precision can also be improved by “drawing 8’s” in the air while holding the device in your hand.