How can I lock my camera on the Y-axis?

Hello! I’ve added a little hover animation to my player ship, but now - as the camera is tracking my player ship - the camera bobs slightly as it tracks the animation.

Is there a way to lock my camera on the Y-axis as to negate this bob?

Here’s my CameraFollow script:

public class CameraFollow : MonoBehaviour {

	public Transform target;
	public float smoothing = 5f;

	Vector3 offset; 

	void Start()
		offset = transform.position - target.position;

	void FixedUpdate ()
		Vector3 targetCamPos = target.position + offset;
		transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);


Thanks in advance for any help!


hmm something like this :

transform.position = Vector3.Lerp (transform.position, new Vector3 (targetCamPos.x , 0.0f , targetCamPos.z) , smoothing * Time.deltaTime);

This may work for you. Thanks.