I have a CharacterController that is rotating to always face where the camera is pointing but I want to lock an axis so that it wont lean back and forth when you look up and down.
void Update() {
CharacterController controller = GetComponent<CharacterController>();
Camera cam = GameObject.Find("CharCam").GetComponent<Camera>();
if (controller.isGrounded) {
currentSpeedX = Input.GetAxis("Horizontal");
currentSpeedZ = Input.GetAxis("Vertical");
moveDirection = new Vector3(currentSpeedX, 0f, currentSpeedZ);
moveDirection = cam.transform.TransformDirection(moveDirection);
transform.rotation = cam.transform.rotation;
moveDirection *= speed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}