# Lock rotation of camera on zoom

Im making a game that involves the player rotating the camera around the planet. This includes the player being able to zoom in and out of the planet. I want it so that the rotation for the y and z components are locked, and the camera angle changes on when the player zooms in and out only in the x plane. How do I achieve this? The code i’ve come up with is below.

``````void LateUpdate (){
if (camTransform.localPosition.z != holderDistance * 1f)
camTransform.localPosition = new Vector3(0f, 0f, Mathf.Lerp(camTransform.localPosition.z, holderDistance * -1f, Time.deltaTime * scrollDampening));

ZoomAngleChange();

}

//Function to change angle on zoom. probably not the best way but Im not sure how else
private ZoomAngleChange(){
Quaternion quat1 = Quaternion.Euler(0f, 0f, 0f);

if (camTransform.localPosition.z >= 0f && camTransform.localPosition.z <= 35f)
{
camTransform.rotation = Quaternion.Lerp(camTransform.rotation, quat1, Time.deltaTime * zoomInAngleDampening);
}
}

//Function to enable zoom in and out
private void Zoom()
{
float zoomAmount = Input.GetAxis("Mouse ScrollWheel") * zoomSensitivity;

zoomAmount *= (holderDistance * slowZoomValue);

holderDistance += zoomAmount * 1f;

//clamp scroll amount
holderDistance = Mathf.Clamp(holderDistance, maxZoom, minZoom);

}
``````

If you only wanted to change rotation on the x axis then maybe try changing the line

`````` camTransform.rotation = Quaternion.Lerp(camTransform.rotation, quat1, Time.deltaTime * zoomInAngleDampening);
``````

to something like this

``````Quaternion rot = Quaternion.Lerp(camTransform.rotation, quat1, Time.deltaTime * zoomInAngleDampening);
camTransform.rotation = Quaternion.Euler(rot.Euler.x, camTransform.rotation.Euler.y, camTransform.rotation.Euler.z)
``````

I think that’s what you’re trying to achieve, although this code is untested. Good luck!