My camera is moving up and down while im rotating it in game how do i fix this?

```
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
public Transform target;
public Vector3 offset;
public bool useOffsetValues;
public float rotateSpeed;
public Transform pivot;
public bool locked;
public float maxViewAngle;
public float minViewAngle;
public bool invertYaxis;
// Start is called before the first frame update
void Start()
{
if (useOffsetValues)
{
offset = target.position - transform.position;
}
pivot.position = target.position;
//pivot.parent = target;
Cursor.lockState = CursorLockMode.Locked;
locked = true;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.U))
{
if (locked)
{
Cursor.lockState = CursorLockMode.None;
locked = false;
}
}
if (Input.GetKeyDown(KeyCode.L))
{
if (!locked)
{
Cursor.lockState = CursorLockMode.Locked;
locked = true;
}
}
}
void LateUpdate()
{
pivot.transform.position = target.transform.position;
float horizontal = Input.GetAxis("Mouse X") * rotateSpeed;
pivot.Rotate(0f, horizontal, 0f);
float vertical = Input.GetAxis("Mouse Y") * rotateSpeed;
//pivot.Rotate(-vertical, 0f, 0f);
if(invertYaxis)
{
pivot.Rotate(vertical, 0f, 0f);
}
else
{
pivot.Rotate(-vertical, 0f, 0f);
}
if (pivot.rotation.eulerAngles.x > maxViewAngle && pivot.rotation.eulerAngles.x < 180.0f)
{
pivot.rotation = Quaternion.Euler(maxViewAngle, pivot.eulerAngles.y, 0.0f);
}
if (pivot.rotation.eulerAngles.x > 180.0f && pivot.rotation.eulerAngles.x < 360f + minViewAngle)
{
pivot.rotation = Quaternion.Euler(360.0f + minViewAngle, pivot.eulerAngles.y, 0.0f);
}
float desiredYAngle = pivot.eulerAngles.y;
float desiredXAngle = pivot.eulerAngles.x;
Quaternion rotation = Quaternion.Euler(desiredXAngle, desiredYAngle, 0f);
transform.position = target.position - (rotation * offset);
if (transform.position.y < target.position.y)
{
transform.position = new Vector3(transform.position.x, target.position.y, transform.position.z);
}
//transform.position = target.position - offset;
transform.LookAt(target);
}
}
```