# Create an unlimited terrain

i have a terrain(named road) i want that terrain to repeat itself when my game object(car) reaches to some position on x direction.terrain must repeat itself just where the first terrain end so that my game object(car) will feel like, its running road where there is no end of road not on two different terrains.something like subway surfer ,(my basic requirement is to create endless runner )i am very new to unity so plz it will be grate help if u explain what to do and how to do.

You need to:

• Create several terrain tiles and map them together so that all of their edges are seamless joins (you could create one terrain and just instantiate it a few times, the easiest may be to have 9)
• As you move you work out which tile you are on and either:

(1) move the other terrain tiles so that they surround the player - this has a problem when you end up a long way from the start due to the inaccuracies in floating point numbers.

``````    TTT
T*T    Move the tiles so that the player is always in the middle
TTT
``````

(2) move the player and all other objects back to the relative position on the central tile when the player exits it by adjusting the x,z coordinates by the size of a tile.

``````    TTT
T*T    Move the player when they exit the central tile so that they are back on it
TTT
``````

You should look into Instantiating Objects, and creating Prefabs. These are basic things that you’ll be doing alot in Unity.

In your example you’d Prefab your Terrain, create a GameObject variable in whatever script you’re using to control the game, then when you want to create the terrain, Instantiate the GameObject and set its transform.localPosition based on the scale of the terrain and how many of the terrains there are (ie, if this is the 5th terrain, and you’re running on the Z direction, you’d set the localPosition to 0,0,NumTerrains * TerrainLength). You’ll also need to keep track of the number of terrains and the last two terrains created so that when you create your next terrain you can Destroy the terrain behind the one you’re on.

I’d run through the Beginner Scripting tutorial which should cover everything you need to know to impliment this