Skip to content

Instantly share code, notes, and snippets.

@rajesh1993
Created March 25, 2020 03:48
Show Gist options
  • Save rajesh1993/5af761cc452f6e39d96d553b13e56039 to your computer and use it in GitHub Desktop.
Save rajesh1993/5af761cc452f6e39d96d553b13e56039 to your computer and use it in GitHub Desktop.
Rotate Camera around Player/Character in Unity
// Rotates the camera around character's current position based on axis input.
// PS4 - Right Analog Stick
void updateCamRotation(Vector3 characterPosition) {
// Set speed of rotation
float rotationSpeed = 2;
// Obtain Axes input.
float rotateHorizontal = Input.GetAxis("RightStickX");
float rotateVertical = Input.GetAxis("RightStickY");
// Rotate camera about the character's current position.
gameObject.transform.RotateAround(characterPosition, Vector3.up, rotateHorizontal * rotationSpeed);
gameObject.transform.RotateAround(characterPosition, transform.right, rotateVertical * rotationSpeed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment