I am new to Unity. I have created some basic camera framework to move the camera around on a top down type view and it does the job but why does the mouse panning seem so smooth but the key moving(w,s,d,a) seem choppy? Code (CSharp): // panning if (Input.GetMouseButton(0)) { transform.Translate(Vector3.right * Time.deltaTime * PanSpeed * (Input.mousePosition.x - Screen.width * 0.5f) / (Screen.width * 0.5f), Space.World); transform.Translate(Vector3.forward * Time.deltaTime * PanSpeed * (Input.mousePosition.y - Screen.height * 0.5f) / (Screen.height * 0.5f), Space.World); } else { if (Input.anyKey) { string keyPressed = Input.inputString; switch (keyPressed) { case "d": transform.Translate(Vector3.right * Time.deltaTime * PanSpeed, Space.Self); break; case "a": transform.Translate(Vector3.left * Time.deltaTime * PanSpeed, Space.Self); break; case "s": transform.Translate(Vector3.down * Time.deltaTime * PanSpeed, Space.Self); break; case "w": transform.Translate(Vector3.up * Time.deltaTime * PanSpeed, Space.Self); break; default: break; } } }
First suggestion would be to use Input.GetAxis rather than what you're doing there. It makes cleaner, easier maintained code, and it also has smoothing and such. This may be the source of your choppiness.