Need help with Smooth and Zoom limit (3D Game)

Hello there. I’m new to unity and C#. I got almost everything i wanted on my camera and that is the camera following my character, the camera collision (with raycast), zoom in and out, but the problem i’m having is that my camera is too stiff and i want to smooth it, but dont know how to do it… Also i want to apply a limit to my zoom in and out, but again i dont know how to do it. Here is the script i made:

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

public class CameraFollow : MonoBehaviour{

public const float Y_ANGLE_MIN = -20.0f;
public const float Y_ANGLE_MAX = 50.0f;
public Transform lookAt;
RaycastHit hit = new RaycastHit ();
public Transform camTransform;
private Camera cam;
public float distance = 40.0f;
public float currentX = 0.0f;
public float currentY = 0.0f;
public float sensitivityX = 4.0f;
public float sensitivityY = 1.0f;

private void Start () {

camTransform = transform;
cam = Camera.main;

GetComponent ().fieldOfView = 20f;
}

private void Update () {

currentX += Input.GetAxis (“Mouse X”) * sensitivityX;
currentY -= Input.GetAxis (“Mouse Y”) * sensitivityY;
currentY = Mathf.Clamp (currentY, Y_ANGLE_MIN, Y_ANGLE_MAX);

if (Input.GetAxis (“Mouse ScrollWheel”) > 0)
{
GetComponent ().fieldOfView–;
}

if (Input.GetAxis (“Mouse ScrollWheel”) < 0)
{
GetComponent ().fieldOfView++;
}
}

private void LateUpdate() {

Vector3 dir = new Vector3 (0, 0, -distance);
Quaternion rotation = Quaternion.Euler (currentY, currentX, 0);
camTransform.position = lookAt.position + rotation * dir;
camTransform.LookAt (lookAt.position);
if (Physics.Linecast (lookAt.position, transform.position, out hit))
transform.position = hit.point + transform.forward * 0.2f;
}
}

I saw a lot of videos and forums about it but i dont know how to adapt my script to make my camera move smoother and zoom limit… Can anyone help me do it?

For starters, use code tags.

Limiting zoom level is as simple as taking the logic you have for Y angles, and applying it to your camera’s fieldOfView.

Smoothing it out is a tougher answer because there are a lot of kinds of smoothing. No matter which case you use, you’ll want to create a targetFieldOfView member variable of your class, and then move the actual fieldOfView towards that a little each frame. I’d suggest adding this line to LateUpdate() for that:

Camera cam = GetComponent<Camera>();
cam.fieldOfView = Mathf.MoveTowards(cam.fieldOfView, targetFieldOfView, Time.deltaTime);

You can add a multiplier to that third parameter if you want to speed up or slow down the rate at which is moves.