Smooth Camera Lerp with Continual Scroll

Hi there, I’m trying to create a nice smooth camera to track a couple of characters. So far I’m using this code and all is well:

void Update()
{

    		newCameraPosition = Vector3.Lerp (currentCameraPosition, averageWorldPositionCharacters, 0.5f);
    		deltaCameraPosition = (newCameraPosition - currentCameraPosition);
      
    		currentCameraPosition = newCameraPosition;
}

and

	void LateUpdate ()
	{
		 
		transform.Translate ( deltaCameraPosition  );
 	
	}

So averageworldposition is a point between the two characters I’m tracking. This works great, but I want to add additional code that will move the camera to the right every frame (in addition to the existing movement code), regardless of the position of the characters (so effectively scroll it right at a consistent velocity - so if the characters became stationary, the camera would continue to move to the right).

I tried to simple add this to deltaCameraPosition, so:

transform.Translate (deltaCameraPosition + new Vector3 ( 1.0f, 0.0f, 0.0f  );

However this produced some unexpected results, I’m assuming becuase I’m moving the lerp target further away each frame, the distance between the current position and lerp target is greater.

Could anyone advise me as to how to achieve this?

Thanks so much.

I’m assuming this is attached to the camera. This code uses ‘transform.position’ rather than currentCameraPosition. ‘speed’ is a variable you define (or hard code a value) that defines the speed of movement when the camera is in front of the characters.

void Update() {
   newCameraPosition = Vector3.Lerp (transform.position, averageWorldPositionCharacters, 0.5f);
   deltaCameraPosition = (newCameraPosition - transform.position);
    
   if (deltaCameraPosition.x <= 0.0f)
       deltaCameraPosition = speed * Time.deltaTime;
}