Lock Third Person player rotation

Hey guys, I want that my third person character has a lock so he don’t rotates over 360°. I hope someone has a solution.

Here’s the mouse rotating script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class LockMouse : MonoBehaviour
{

public float mouseSensitivity = 500f;
public Transform playerBody;

float xRotation = 0f;

// Start is called before the first frame update
void Start()
{
  Cursor.lockState = CursorLockMode.Locked;
}

// Update is called once per frame
void Update()
{
    float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
    //float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;

    xRotation -= mouseX;
    xRotation = Mathf.Clamp(-180, xRotation, 180);

    playerBody.Rotate(Vector3.up * mouseX);

}

}

Change last two lines like this:

xRotation = Mathf.Clamp(xRotation, -180, 180);
playerBody.rotation = Quaternion.AngleAxis(xRotation, Vector3.up);

Good Lock :slight_smile:

Thank you very much, it worked very well!