Scrolling background help - seams appearing...

Hi there,

I have the following code that I am using for a background that I want to scroll left and right, repeating. Unfortunately, I am getting a gap between the objects… sometimes it overlaps, other times there is the gap… is there any more precise way to scroll two objects as one?

private var fLeftPosition = -21.07282;
private var fRightPosition = 21.07282;


function Update () 
{

	transform.localPosition.z = 5.785643; // Locks the Z position
	
	// When reaches left limit, reset position
	if (transform.localPosition.x < (fLeftPosition * 2))
	{
		transform.localPosition.x = (fRightPosition * 2);
	}
	// When reaches right limit, reset position
	else if (transform.localPosition.x > (fRightPosition * 2))
	{
		transform.localPosition.x = (fLeftPosition * 2);
	}
	
	// Move background when turning left and right
	if (PlayerControl.g_bPlayerOneIsTurningLeft == true)
	{
		transform.Translate((-PlayerControl.g_fRotationSpeed / 5) * Time.deltaTime, 0, 0);
	}	
	else if (PlayerControl.g_bPlayerOneIsTurningRight == true)
	{
		transform.Translate((PlayerControl.g_fRotationSpeed / 5) * Time.deltaTime, 0, 0);
	}
	else
	{
		transform.Translate(0, 0, 0);	
	}
}

Instead of, when the object get’s too far left/right directly setting the position back to the other far right/left position add the length difference to them.

What you’re doing now is saying if you’re too far left, meaning it’s position is minLeft + a bit, go to far right. But the position of the second on is then offset by that ‘a bit’.

So replace

transform.localPosition.x = (fRightPosition * 2);

with

transform.localPosition.x += (fRightPosition * 2)-(fLeftPosition * 2);