How to restrict camera movemetn alaong the y axsis?

Hello,

I am trying to create a smooth camera movement script. I have been able to get the smooth movement that I wanted but the gameobject that the camera follows moves forwards as well as bounces up and down. I only want the camera to follow the gameobject when it is moving forwards and not when the gameobject is bouncing. I am looking for a way to have it where I can restrict the movent of the camera along the x-axis. Here is the script that is on the camera

public Transform target;

public float smoothSpeed = 0.125f;

public Vector3 offset;

private void FixedUpdate()
{
    Vector3 desiredPosition = target.position + offset;
    Vector3 smoothedPosition = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed);
    transform.position = smoothedPosition;

} 

If anybody has any suggestion stat would be great!

Thanks!

Cinemachine will work perfectly. Furthermore, camera movements should be done on void LateUpdate
and not void FixedUpdate

Hi,

Have you tried using cinemachine? It’s free from the package manager, and easy to use. There are lots of tutorials on youtube about how to use it. Setting it up to do this should be easy.