Creating infinite terrain.

Hello everyone, I’m working on trying to create a side scrolling space shooter and I would like the game to have an arcade style play where you just go until you run out of lives. I am not sure how to work the terrain in some aspects. Mainly what I want to do is create an infinite tunnel that you fight your way through. My only idea thus far (I’m still fairly new to unity and even newer to C# coding.) is to model out and import level chunks and have the game call them in as you move along creating a randomized infinite level. This is a project for school and is my first programming class but I wanted to do something a little more than just float through. I would like to make this into more than just a project once I finish my class. As far as the level goes, I’m not sure if doing it this way would be good / relatively easy or if there is a better way to generate the terrain. Any help would be appreciated.

What you are basically doing is an infinite runner. I have never made one before nor had any interest in doing so, so I would be of little help there. But knowing that you are making an infinite runner I would set out and look into methodologies of making one. There are also some nifty packages in the Unity store already set up for it.

1 Like

Hello!

What i tend to do is to create a few tiles and join them together. these make up the background/world.
I then check to see if they are behind the camera and if they are i just place them at the end again.

I also prefer moving the world instead of the player whenever possible, so the player can stay at 0,0,0.

I’m terrible at explaining with words, but i recorded 2 vids for you to check out so you can see how it works.

This one is of a multi-directional scroller in 2d that i scrapped:

(I’m moving the player and the world in this project because i was using rigid bodies. so to deal with the player getting reset to 0,0,0 every now and then i parented all objects to the player)

This next one is from the first game i made:

(in this one i’m only moving the world at a constant speed towards the player and the only movement the player does is along the X and Y axis.)

It should give you some idea on how the “terrain/world” part works. With some clever tiling and a function that picks a new random tile you can give the impression that it isn’t the same terrain just being shifted around.

1 Like

Thanks a lot for the help and ideas. BlueSin i’ve been watching some tutorials on making infinite runners to get an idea of how those work and to try and adapt the code to my game.

I’ve watched a few infinite runner tutorials to figure out how they work. Most of them are pretty good about showing the code so it’s not terribly hard to look at it and use the logic from their codes and rewrite it. Thanks for the idea.

My biggest question is more or less did you build the terrain in chunks and have the game call them in at random or did you have a tool that created it as the game went on?

I built them in chunks and then i have the game call them in at random depending on which chunk it will be next to :slight_smile: