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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Random Level Generation

Discussion in 'General Discussion' started by DilaraAK, Nov 27, 2022.

  1. DilaraAK

    DilaraAK

    Joined:
    Sep 17, 2020
    Posts:
    3
    "With the level generator, each level will be randomly generated automatically." How can I do this in Unity? Does it mean the generator will put assets automatically in the scene, do you have any idea?
     
  2. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,925
    To make a decent random level, you have to do all of the hard work yourself. Unity has no option for that. Even if all you want is "just anywhere, but no overlaps" you'll have to work to avoid those overlaps. Then you'll realize that looks like garbage, even though it is "random" and have to do the work yourself to improve it.

    But where did you read this? If this is an asset that someone says will make random levels, then they did all the work. All you do is install it, follow the directions, and you'll get random levels. BUT, there's all sorts ways to make random levels, some nicer than others.
     
  3. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    486
    And dont forget about GI, a random generated world means no static geo which means no GI.
     
    DilaraAK likes this.
  4. DilaraAK

    DilaraAK

    Joined:
    Sep 17, 2020
    Posts:
    3
    Thank you, yeah it seems like hard work actually. I got a case and it is written "With the level generator, each level will be randomly generated automatically." I did not get actually what they mean so I wanted to ask here. It is a runner game and I just have player and some obstacles, basic hypercasual game. Idk is there a way to level generation for that?
     
  5. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,519
    I expect that random generation is standard for that. Isn't this just randomising the placement of obstacles?

    Of course it can't be fully random if you want playable results, you'll need some rules for what is valid. For instance, you can't block all lanes.
     
  6. MadeFromPolygons

    MadeFromPolygons

    Joined:
    Oct 5, 2013
    Posts:
    3,883
    These will give you an idea of just some of the ways to go about generating a level. The basic underlying principles are the mostly the same for 2D or 3D, so I recommend trying 2d first to get to grips without the addition of a 3rd dimension:

    https://gamedevacademy.org/understanding-procedural-dungeon-generation-in-unity/





    Ofcourse this assumes you want to generate even the level geometry (either from scratch or from kit pieces/prefabs).

    Otherwise its mostly just a case of sampling a bunch of positions to spawn/position prefabs which is pretty simple.
     
  7. lmbarns

    lmbarns

    Joined:
    Jul 14, 2011
    Posts:
    1,628
    With an endless runner you usually create chunks/tiles of track/road, and do like a carrousel where it scrolls (or the character moves forward) and when a back chunk moves beyond a point behind the player it appends back onto the opposite end (front). When a chunk moves to the front you randomly place obstacles or may just toggle random obstacles on/off so it's different each time it passes by.
     
    stain2319 likes this.
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,184
    You can have global illumination in a generated world with the easiest by far being one of the several real-time global illumination systems on the asset store. If performance is a major concern for a project you can save the lightmapping data you need to the prefab and when the prefab is instantiated the lightmap will come with it.

    https://assetstore.unity.com/?q=global illumination
    https://github.com/Ayfel/PrefabLightmapping