Skip to content

Instantly share code, notes, and snippets.

@ProfessorSalty
Created October 30, 2022 20:22
Show Gist options
  • Save ProfessorSalty/0d53200393c3c7c20c898a687a990e84 to your computer and use it in GitHub Desktop.
Save ProfessorSalty/0d53200393c3c7c20c898a687a990e84 to your computer and use it in GitHub Desktop.
// left & right, only rotate the body
var horizontalInput = Input.GetAxisRaw("Horizontal"); // -1 ... 1
transform.rotation = Quaternion.Euler(new Vector2(0, horizontalInput * sensitivity));
// up & down, only rotate the camera
var verticalInput = Input.GetAxisRaw("Vertical");
var constrainedInput = Mathf.Clamp(verticalInput * sensitivity, -maxRotation, maxRotation);
// get the camera and apply rotation
Camera.main.transform.rotation = Quaternion.Euler(new Vector2(constrainedInput, 0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment