Created
March 25, 2020 03:48
-
-
Save rajesh1993/5af761cc452f6e39d96d553b13e56039 to your computer and use it in GitHub Desktop.
Rotate Camera around Player/Character in Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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