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!