Tutorial: Randomly Generating 2D Terrain in Unity

I thought I would throw together a simple tutorial to demonstrate how to generate terrain randomly in a 2D game using Unity.

This terrain generation would be suited to platformers specifically endless runners.

This tutorial would be more aimed at beginners.

Link: Randomly Generating 2D Terrain in Unity

This is my first written tutorial so any feedback would be helpful.

Thanks

Made some updates and corrected a few mistakes.

will check out thanks

1 Like

Thanks man! :slight_smile:

I assume this’ll also work games other than side-scrolling jump&runs, specifically for top-down perspective 2d?

Haven’t looked into it in detail yet (my project is far from that point, but this is definitely on my “to read” for later on), but any hints on which kinds of adjustments would have to be made compared to the tutorial?

1 Like

Sorry for the late reply man. I am not sure what would be best for your game as I don’t know the specifics.

They way my very simple tutorial works is using the cameras placement to generate terrain to the right of it. You could change that to generate above, below etc but I would think for your game maybe it might be better to figure out a way to randomly generate the whole level at the start like spelunky does. I would guess to do this you would have some terrain prefabs and a script that neatly stitches them all together as the level loads.

There is no need to apologize for providing your free help with a delay.
My project is luckily under no time pressure. (If it was I’d be pretty screwed due to the weather, can’t really think straight in a 35°C room so I’m only putting in half as many hours per week into the project for the next few months.)

Anyway, now that I’ve had time to look through the tutorial (which did help me with quite a few things on which I didn’t even know how to begin) it does sound more sensible for my project to generate the terrain once upon loading a level (though it could be funny to use the camera-bound terrain generation to simulate an infinite void or an impossibly huge desert). It’s been a help already. :slight_smile:

1 Like

That is super awesome to hear :smile:

Hey, just a quick thank you and update. Thanks for all the views, my personal website has got a load of hits through this post which is awesome.
I am just getting around to updating my site and putting together a few more tutorials. A simple 2D Space Shooter, Volume Controls, 2D Pong, Mobile Friendly Camera etc. Will post here when each new tutorial happens. Expect the first and the beginning of next week. Thanks again.