Accelerometer Quick Question(Moving Up and Down?)

So lately I’ve been messing around with the Accelerometer code in the tutorials for Unity, and I was wondering how can I get my game object to move up and down on the Y axis instead of the X? You see I use this little piece of code so far:

void Update() {
		transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
	}
}

So this moves my game object right and left when I tilt the device right or left. Which is amazing but I’m trying to move it up or down when I tilt up or down. Changing the first Input.acceleration from x to y only changes the controls, but doesn’t change the movement of the game object. I know this is a very basic question, so scold me if you must. Also don’t worry I’ve checked other answers and they seem to use a different method than the one in the tutorial(the one I’m using), so it makes it harder to understand fully without copying someone else’s code.

The Translate function takes three parameters which are:

transform.Translate(x, y, z);

Well actually it has a couple other optional parameters (see docs)
So if you want to move the object along its y axis (up and down) you will probably want something along the lines of:

transform.Translate(0, Input.acceleration.y, -Input.acceleration.z);

The first parameter is 0 because you don’t want the object to move along its x axis.
The second value (objects y) is being modified by the y acceleration value.
Here’s a link to the documentation: http://docs.unity3d.com/ScriptReference/Transform.Translate.html

Hope that helped :slight_smile: