Search Unity

Endless Falling Thoughts

Discussion in 'Scripting' started by T27M, Sep 19, 2014.

  1. T27M

    T27M

    Joined:
    Sep 19, 2012
    Posts:
    3
    Hello All

    I'm looking for some opinions on the current way I have designed our 2D game. One of the modes is an endless mode where the player keeps falling and the level is generated as the player falls.

    A quick look shows that there could be potential issues in just letting the player fall and other have said that they don't like the results when the player is limited in movement and the world moves up underneath the player.

    I went for another technique which was to split the game world into sections, each section is prefab that is manually created, but each element of the prefab can be set somewhat randomly so that two sections never look alike. There is two sections at the top of the playable level and two at the bottom of the playable level, these sections (top and bottom) are always are always the same as each other, but the player can only ever see a small part of each section at any time. Separating the top of the level and the bottom of the level are 3 more randomly generated sections.

    The player falls naturally using a rigidbody. When the player gets half way down the level, the two top sections and two bottom sections are randomly regenerated (the player won't see this happen). Keep in mind the top two sections are now identical to the bottom two sections. When the player reaches the last section, just before the player enters the section he is teleported back to the top of the level, right in between the two identical sections he just left. From the players perspective nothing looks different, but actually he moved up (Y) in the gameworld by a couple hundred units. From there the cycle repeats, the player never travels more than ~400 units from the starting point and the entire playable gameworld never goes greater than ~500 x ~200 units.

    Now obviously this means I have to keep track of everything that is visible in the two sections and ensure that they are identical so that (from the players perspective) nothing suddenly appears out of thin air, when in reality the player was teleported to a similar, but not identical part of the map.

    DSC_0142.JPG

    • Must work on mobile
    • I'm using transform.position to "teleport" the player
    • I'm pooling the random objects and to regenerate them I simply shuffle the positions around and/or change the sprite.
    1. Is there an easier way?
    2. Can anyone see any issues that might arise from using this method?
     
  2. BmxGrilled

    BmxGrilled

    Joined:
    Jan 27, 2014
    Posts:
    239
    Your idea is good, one suggestion is to have only the visible section created, and have that parented to a "section" parent object. as the player falls, they hit a trigger collider, which moves the player AND the section object up. A new section object is created, the previous lastSection object destroyed. So you have 3 sections like you describe, but since they're parented to one object for each section, when you move that one object it moves everything in that section. Hope this helps! :)
     
  3. T27M

    T27M

    Joined:
    Sep 19, 2012
    Posts:
    3
    Hmm, that's something to think about. The sections have quite a lot of colliders attached, not sure how much it would effect performance by moving them around.
     
  4. BmxGrilled

    BmxGrilled

    Joined:
    Jan 27, 2014
    Posts:
    239
    How many colliders would you estimate there are?
    if it's only about 10-20 I wouldn't worry about it :)
    I'm not really sure what a mobile's capacity is beyond 20, I don't develop for mobile.
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Test it, don't guess it :)
     
    BmxGrilled likes this.