Search Unity

Make an endless levels spawn randomly?

Discussion in 'Getting Started' started by Koval331, Feb 20, 2019.

  1. Koval331

    Koval331

    Joined:
    Feb 3, 2019
    Posts:
    114
    So I want to create a game similar to those mobile endless runners where you run/fly forward/up/down and the level sections premade by the game developer are looping infinetly in the game.

    What is the best way to do that? Scenes, prefabs, other fancy feature?
     
  2. DaDonik

    DaDonik

    Joined:
    Jun 17, 2013
    Posts:
    258
    Well first you need an object pooler, so you can recycle everything behind the player and respawn it in front of the player.
    Then you would probably build some prefabs with models that are ideally modeled on a grid, so you can seamlessly put them together. After that you need to figure out some logic that spawns your prefabs from your pool into the world and puts them back into the pool when the player has passed them. You also have to reset the player position to the world origin after a while, otherwise you will see that things start to jitter (google: floating point inaccuracy).
    Thats basically it.

    You can also have a look on the asset store. A friend of mine has made an asset that does exactly what you need: 'Ouroboros'.
    It does everything i said and a whole lot more. You will still need to make/buy the 3D models, though.