Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Tutorial: Randomly Generating 2D Terrain in Unity

Discussion in 'Community Learning & Teaching' started by StevenMcS, Jun 2, 2014.

  1. StevenMcS

    StevenMcS

    Joined:
    Sep 29, 2013
    Posts:
    61
    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
     
  2. StevenMcS

    StevenMcS

    Joined:
    Sep 29, 2013
    Posts:
    61
    Made some updates and corrected a few mistakes.
     
  3. ProjectOne

    ProjectOne

    Joined:
    Aug 9, 2010
    Posts:
    442
    will check out thanks
     
    StevenMcS likes this.
  4. StevenMcS

    StevenMcS

    Joined:
    Sep 29, 2013
    Posts:
    61
    Thanks man! :)
     
  5. Shoat

    Shoat

    Joined:
    Jun 2, 2014
    Posts:
    5
    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?
     
    StevenMcS likes this.
  6. StevenMcS

    StevenMcS

    Joined:
    Sep 29, 2013
    Posts:
    61
    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.
     
  7. Shoat

    Shoat

    Joined:
    Jun 2, 2014
    Posts:
    5
    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. :)
     
    StevenMcS likes this.
  8. StevenMcS

    StevenMcS

    Joined:
    Sep 29, 2013
    Posts:
    61
    That is super awesome to hear :D
     
  9. StevenMcS

    StevenMcS

    Joined:
    Sep 29, 2013
    Posts:
    61
    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.