Y is increasing even when X is being changed

I’m having trouble with a 2-D game I’m attempting to make. Every time I give the game any input that is relevant to the axis, the Y increases greatly. I’m semi-new at this, so I’m going to post the code and would like to see if anyone knows the problem here.

public class Player : MonoBehaviour {

	public float health = 100f;
	public float speed = 1.0f;
	private Vector3 moveDirection = Vector3.zero;

	// Use this for initialization
	void Start () {
	}

	// Update is called once per frame
	void Update () {

		CharacterController controller = GetComponent<CharacterController>();
		moveDirection = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0);
		moveDirection = transform.TransformDirection(moveDirection);
		//Multiply it by speed.
		moveDirection *= speed;
		controller.Move(moveDirection * Time.deltaTime);

	}
}

Thank you!

You’re using transform.TransformDirection which is converting “moveDirection” into world space. I am not sure how you are accomplishing a 2D game, but your local axis may not be aligned with your world axis.

Best way to determine what exactly is happening is to post some breakpoints on those lines of code operating on moveDirection and watch where the y value is, first, pulled from the Axis API, and then after you transform it with TransformDirection.