Search Unity

How does Crossy Road generate a different environment layout each time you play?

Discussion in 'Game Design' started by gibble55, Nov 12, 2015.

  1. gibble55

    gibble55

    Joined:
    Sep 21, 2015
    Posts:
    9
    How does Crossy Road generate a different environment layout each time you play? Each time I play the game, it has a completely different layout.

    I want to do this for my 2D app and I was thinking of making 5 or so different layouts and then randomly choosing a different scene each time but I do not know how to do this. I would appreciate your suggestions.

    Thanks in advance!
     
  2. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    They won't have any prebuilt scenes, they would have built a bunch of prefabs, I'd say each road would be a prefab, then at runtime they will randomly choose the next road segment as the player progresses. simply Instantiate it and place it in the next position along the level.

    How you build a random level generator is really dependant on the game you're building. What works for Crossy Road may or may not work for you. It really depends on what you're going for.
     
    gibble55 likes this.
  3. Dennis_eA

    Dennis_eA

    Joined:
    Jan 17, 2011
    Posts:
    380
    You could use Random.Range to get a random integer every time the player starts a game, based on this value the game could use a different set of models or another texture atlas.
    Also, you could get the time on the user's device and make a darker/night theme when its..night. or something? :)

    Antony said something about instantiating; I suggest to get your head around pooling :) ;)
     
    gibble55 likes this.
  4. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Well yeah, I'd say just use instantiate and then use pooling if performance is an issue later. Pooling is always useful but at the same time there's not a lot of point thinking about optimisation if you don't have the correct behaviour yet.
     
    gibble55 likes this.
  5. Dennis_eA

    Dennis_eA

    Joined:
    Jan 17, 2011
    Posts:
    380
    I didn't want to sound like ..instantiating? well I know something better, newb. :eek::D what I meant, the OP should put that on his list. just this :cool:;)
     
    gibble55 likes this.
  6. gibble55

    gibble55

    Joined:
    Sep 21, 2015
    Posts:
    9
    Thanks a bunch for your responses, Dennis and Antony. Your suggestions are appreciated.

    Random.Range: this seems a more practical approach. I would love to hear more about what you are suggesting, Dennis.

    I think I understand what you are referring too but as a Newbie, I am not exactly sure how to execute this. What I am trying to achieve is fairly simple, please see the attached mock up.

    Prefabs/Scene Level Generator: That could work. How exactly would I execute this? (yes, Antony - my head was spinning :) Building a random level generator sounds like a great idea, I am not sure how to achieve this though. Have you seen and tutorials or assets that offer this?

    Mock up: as you will see by the attached image, I just want the levels to to placed in different positions each time the game starts over.
     

    Attached Files:

  7. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    By random level generator, I mean any piece of code that randomly assembles some type of level. A random level generator could be as simple as placing a single object in a random position all the way up to the crazy stuff those guys are doing on No Man's Sky.

    How I usually approach it is I build levels I want the game to look like by hand. Only after that will you understand exactly what it is you'll want to randomise using something like the Random class in Unity to select random positions, rotations, and prefabs out of possible level pieces, etc.

    The other benefit of building a few levels by hand first is it'll help you more quickly define your gameplay without annoying bad level generation bugs getting in the way and confusing things.