Third Person Camera - Issues with rotation

I am trying to write a simple TPS camera. I want the camera to turn an object on the horizontal axis. When looking down I want the camera to move up the more you look down until you are looking at the feet with the camera slightly above the head. I want the camera to move down the back as you move the camera looking towards the sky. My problem is, I can not figure out how to get the camera to look up and down correctly or with any type of limit. I can spin the camera in a complete 360 when looking up or down so it will spin in place. Here is my code

public class FollowCamera : MonoBehaviour
    public GameObject target;
    public float rotateSpeed = 5f;

    void Start()
        transform.parent = target.transform;


    void LateUpdate()
        float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
        float vertical = Input.GetAxis("Mouse Y") * rotateSpeed;
        target.transform.Rotate(0f, horizontal, 0f);

        this.transform.Rotate(-vertical, 0f, 0f);


You can access the camera rotation by using transform.eulerAngles, and limiting the camera look up rotation by doing:

transform.eulerAngles.x = Mathf.Clamp(transform.eulerAngles.x, -90, 90);

You may also will wan’t to try cinemachine, it’s Unity’s opensource camera solution Download Link