moving background

i want to make a repetitive moving background in my 2d platformer.
for this i use two boxes with a 16:9 scale with a repetitive texture on it.

i move it with this script:

function FixedUpdate () {
	transform.position.x  -= 0.05;
	
////replace	
	
	if ( transform.position.x <= -11){
		transform.position.x = 21;
	}
}

it works but i got a bad looking stripe between the boxes. same with planes.

got someone an idea to do this with another way?

Two objects under different transforms (be they boxes, planes, or whatever) are unlikely to match up exactly at the shared edge, and any difference at all will have the potential to introduce the kind of visual artifacts you’re seeing.

A better solution would probably be to use a single surface with a tiled texture/material on it.

thank you for your answer.

now i use a 32:9 box with a tiled texture. I thought it would be impossible to not see the resetting but it works perfect.

Hello, I have the exact same problem. I use 2 textures and when the first one goes off the screen I put it behind the second one and if the second one goes off the screen I put it behind the first one and so on.

How did you manage to do it perfectly and with 1 texture? I can’t figure out a way to achieve that…

You simply have to change the texture offset on your material. Have no exact code, as I’m at work. But you can change the texture offset in inspector as well as in code. That’s of course, if the texture is tileable

my texture was 1024x512. so for this you have to use a 32x9 format box instead of a 16x9 box and set the x-tiling of the material to 2.
if the first half of this box is out of screen you can reset the position.

this is my code on the background:

function FixedUpdate () {
	
////move with the actual movingspeed/10 from the MovePlatform2 script	
	
	var backgroundmoving = MovePlatform2.movingspeed/10;
	transform.position.x  -= backgroundmoving;
	//print (backgroundmoving);
	
////replace	
	
	if ( transform.position.x <= -3){
		transform.position.x = 13;
	}
}

Thank you for your answers. I though seem to have a bit of a different problem. I dont use repeating texture but one big texture with different graphics on it(you can think of it as different clouds or houses moving at the background). The end and start of the texture match though.

I solved the problem at the moment with a texture that runs at the meeting point of the 2 textures. The “patch” is transparent on both ends and solid in the middle so it fades quite smoothly from one texture to another.

Of course(if you understand my case) this is far from a good solution but it kind of does the trick at the moment.