Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to start Infinite Runner game Development.

Discussion in 'Getting Started' started by SuperMeta-Studios, Apr 13, 2018.

  1. SuperMeta-Studios

    SuperMeta-Studios

    Joined:
    Apr 30, 2014
    Posts:
    4
    I've been developing games for past four months just to get a good understanding on how Unity works, still a noob though. I want to try creating a Endless runner type game similar to Subway Surfers (how cliche!) for myself, just for practice. My question is what's the best way to set it up? The game has 10 levels, lets just call it sections, that spawn one after the other (in random order) each containing obstacles and other stuff, that are either pooled or manually placed. Do I create each section as new Levels and then load new levels with triggers or should I create a Gameobject that contain all the objects for the particular level?

    If I go with Separate levels for each sections, The game freezes a bit before a new level is loaded and the whole setup way is way complicated for me at this point.

    If I go separate Gameobject for each sections; some section are, lets say, 100 world units and some are just 50 and some even less. How to make each gameobject to spawn at the end (I can use boxcollider to get the collider size) of the section?

    Sorry I've asked a lot questions here, but i've been having sleepless nights trying to figure this.

    Thank you in Advance.
     
  2. Billy4184

    Billy4184

    Joined:
    Jul 7, 2014
    Posts:
    6,008
    As far as I know, subway surfers levels are built on-the-fly in a straight line. The player stays at (0,0,0) and the level gets moved backward, and the levels are deformed into curves by vertex shaders according to the world z position. I made a runner for fun this way some time ago, so I know it works.

    So you just need to determine the rules that the level is built with, and create only as much as the player can see.
     
  3. THoeppner

    THoeppner

    Joined:
    Oct 10, 2012
    Posts:
    205
    SuperMeta-Studios likes this.
  4. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    I think the best way to go would be each section is a scene and the UI/player is it's own scene or scenes then you load in the next scene asynchronously ready to be used and delete/hide-recycle the last scene (this would be memory/performance dependent so test on target hardware).

    Using scenes would get around the clunkyness of nested prefabs (e.g. you have streetlight prefabs along a road prefab and want to change some of them).

    You would have to ensure the scene have a single root transform so you could move them easily as I think they would load by default at position 0,0,0?
     
    Last edited: Apr 14, 2018
    SuperMeta-Studios likes this.
  5. Sailendu

    Sailendu

    Joined:
    Jul 23, 2009
    Posts:
    254
  6. SuperMeta-Studios

    SuperMeta-Studios

    Joined:
    Apr 30, 2014
    Posts:
    4
    Yes the default position is at 0,0,0. I did not know about "asynchronous" scene loading. I tried before without it, every time a scene loads, it kinda freezes before it loads the new level.
     
  7. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    We developed Top Gear: Race the Stig, a 3-lane infinite runner similar to Subway Surfers.

    All the sections (chunks we called them) are in one scene. Each chunk is a hierarchy of game objects. The chunks are pooled and there are multiple instances of each. The player remained at x=0 z=0 and the chunks were pulled from the pool, moved from beyond the far clip plane towards the player (Z axis) and then returned to the pool once behind the camera. Chunks were moved in the X axis as the player changed lanes. The player could move in the Y axis (jumping, etc).
     
    SuperMeta-Studios likes this.
  8. Arowx

    Arowx

    Joined:
    Nov 12, 2009
    Posts:
    8,194
    Last edited: Apr 16, 2018
    SuperMeta-Studios likes this.
  9. SuperMeta-Studios

    SuperMeta-Studios

    Joined:
    Apr 30, 2014
    Posts:
    4
    Thank you. So each "Chunks" contains all the obstacles and stuff in them? and are they placed manually or randomly pooled? Are all the chunks are same size (Z axis)?
    How did you place next chunk at the end of current chunk? This is something I've been working on for a while, but couldn't figure out.

    BTW Race the Stig looks awesome!
     
    Last edited: Apr 17, 2018
  10. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    Thanks.

    I just opened the project for the first time in a couple of years to remind myself how it works - it doesn't even run now :-(

    The chunks are variable sized (length). They act as placeholders really. See image below. The squares represent where the scenery props will go (5 left, and 5 right in this example). The scenery props will be picked from a pool at random. The black object are obstacle props - some static, some dynamic. They're not supposed to be black btw, just some sort of bug due to a newer Unity version. The position of the dynamic ones is driven off the chunk's position, e.g. as a chunk moves towards the player at (0,0) a car will move towards the player at a different speed (it's position relative to the chunk is changing). The obstacles are also picked randomly from a pool, but the type is predefined, e.g. it's always a truck, but the appearance of it will change. The yellow boxes are where collectable nuts (like coins) are placed.

    The chunks themselves are randomly picked and spawned. Yes it's all done on the Z axis. If you know the last chunk's position and length, then you know where the next chunk needs to be positioned.

    Chunk.PNG

    Scenery Props. Note that the actual road is part of the left hand props. The left and right props will be picked at random so they won't necessarily pair up like show here.

    Scenery Props.PNG

    Obstacle Props. Various static and dynamic objects that go on the road.

    Obstacle Props.PNG
     
    SuperMeta-Studios likes this.
  11. Sailendu

    Sailendu

    Joined:
    Jul 23, 2009
    Posts:
    254
    Thanks for posting this info here, I like the idea of keeping the road attached to the left so that the pairing will not be same everytime. I just downloaded the game from the App Store, nice game. I like how the curve changes from left to right sometimes and not just curved towards the left like other similar games. Do you have any plans for updating the game for iPhone X?
     
  12. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    I doubt it will be ever updated again.
     
  13. SuperMeta-Studios

    SuperMeta-Studios

    Joined:
    Apr 30, 2014
    Posts:
    4
    Thank you very much for posting. These are very useful information. Any plans to release this In Unity Asset Store?
     
  14. andymads

    andymads

    Joined:
    Jun 16, 2011
    Posts:
    1,614
    No.
     
    SuperMeta-Studios likes this.