Ground Doesn't Move Correctly [SOLVED]

I used the code for moving the ground from the Runner Tutorial, but when I run it, the whole ground moves to the rightmost edge instead of just one tile.

Code from tutorial:

local pieces = { "ground0", "ground1", "ground2", "ground3",
"ground4", "ground5", "ground6" } 

function init(self) 
	self.speed = 360
end

function update(self, dt) 
	for i, p in ipairs(pieces) do 
		local pos = go.get_position(p)
		if pos.x <= -228 then 
			pos.x = 1368 + (pos.x + 228)
		end
		pos.x = pos.x - self.speed * dt
		go.set_position(pos, p)
	end
end

Can you post a screenshot of your ‘ground.collection’? The code seems to be fine. Do you get any errors in the console?

1 Like

This is ground.collection:

I didn’t get any errors in the console.

Could you please check that the sprites in each of these ground0-6 game objects are at 0,0 and that it is the game objects themselves that have been spaced out one after the other?

1 Like

Thank you for your advice, now it works! I changed the x-positions of the sprites to 190 instead so that it is aligned at (0, 0).