Question by
roypettergamer · Jan 26, 2020 at 10:40 PM ·
rotationthird-person-camera
How do i rotate third person camera around my character while holding down right mouse button?
Hey, i want to rotate my third person camera around my character when i hold down right click. How do i do this?
My Script:
public class ThirdPersonCameraController : MonoBehaviour
{
public float RotationSpeed = 1;
public Transform Target, Player;
float mouseX, mouseY;
// Start is called before the first frame update
void Start()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
void LateUpdate()
{
CamControl();
}
void CamControl()
{
mouseX += Input.GetAxis("Mouse X") * RotationSpeed;
mouseY -= Input.GetAxis("Mouse Y") * RotationSpeed;
mouseY = Mathf.Clamp(mouseY, -35, 60);
// Will control the max u can look up and down
transform.LookAt(Target);
Target.rotation = Quaternion.Euler(mouseY, mouseX, 0);
Player.rotation = Quaternion.Euler(0, mouseX, 0);
}
}
Comment
Your answer
Follow this Question
Related Questions
Camera Follow Behind A Rolling Ball 1 Answer
Third Person Camera - Issues to clamp rotation 0 Answers
Camera Controller script as a child object,Camera Control as a Child Object for my Player 0 Answers
Object Rotation With Touch 0 Answers
Gyro Rotation Offest Calculation or Alternate Solution? 1 Answer