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

3d Endless Runner World Generation

Discussion in 'Scripting' started by SirBumRush, Sep 29, 2014.

  1. SirBumRush

    SirBumRush

    Joined:
    Apr 7, 2014
    Posts:
    5
    Hello, I'm trying to create an Endless Runner game with the Player moving while the Prefab Road is still and continues to generate, making it endless.

    Can anyone help me with this?

    Any links, tips and or advice would be appreciated.
     
  2. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    490
    Prefab road? Can you show an example?
     
  3. Vipsu

    Vipsu

    Joined:
    Oct 8, 2012
    Posts:
    88
    The trick about making character run endlessly is to stop him from moving at all.

    You do this by moving/looping the background/level instead. This way you can spawn new areas and challenges in front of the player and clean them up, after he has finished the challenges.
     
    ZO5KmUG6R likes this.
  4. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Well, you can also move the player but you probably shouldn't go too far due to some precision issues and i'm not quite sure if it leads to any performance problems when running too far. I think it also depends on the complexity of the scene.
     
  5. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    490
    Building on to these 2 ideas. You can also move the player and teleport them back to the beginning when they reach the "end". Seamless loop and it would probably be the easiest .
     
    SirBumRush likes this.
  6. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    I do something similar in my current project.
    It's also an arcade runner game, i do not reset it often but as soon as i get to a certain offset. When i started to develop the game i also thought about the idea mentioned by Vipsu, but as i use a CharacterController it was more reliable to move the character due to the collision detection.
     
    SirBumRush likes this.
  7. Vipsu

    Vipsu

    Joined:
    Oct 8, 2012
    Posts:
    88
    Personally I never use character controller provided by Unity, I always make them myself. Having multiple CC's in the scene (20+) all calling move or simple move methods dropped my fps to something like 1-5. I doubt it was meant for anything else than simple testing.

    Collision works the same for both methods. You can add kinematic rigidbody to your moving obstacles / level pieces / world
    and it will send out collision events to the player. Problem is how you want to handle the collision as player position will likely be constrained but that's a problem for both. .
     
  8. rrh

    rrh

    Joined:
    Jul 12, 2012
    Posts:
    331
    I have two tile-based endless runner puzzle games up on my Gamejolt.

    The jist of what I do there is, in an Update, I translate the treadmill backwards, speed*Time.deltaTime.
    If the position.z is less than -offsetVectorZ, then I
    translate by positive offsetVectorZ,
    then I translate the player by -offsetVector
    then loop through all the tiles and translate them by -offsetVector
    then I loop through the tiles and offset their position in the tiles array (I would also destroy them if necessary but I have a different means of deciding when to destroy them)
    then I generate new tiles to populate the newly empy spaces in the tiles array


    I keep track of them in the array for the puzzle component of the game, so you might be able to leave some of that out.
     
    Last edited: Sep 30, 2014
  9. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Fortunately i only need one CC and the built is enough for the stuff i'm doing. :)
    But ofc i've tested different ways and this pretty much fits my needs. I can mark the other stuff as static and also don't have weird problems when moving objects that are supposed to be snapped to each other (i know could add some extra models which hides these transitions).

    All in all it's working pretty well, but that's up to everyone's desires and also depends on individual needs.
     
  10. Fraconte

    Fraconte

    Joined:
    Dec 6, 2013
    Posts:
    327
    You can try this script that replicate your terrain all around your character and updates when he move near the bounds.

    The link to the file is in the youtube page.
     
  11. SirBumRush

    SirBumRush

    Joined:
    Apr 7, 2014
    Posts:
    5
    The Player is going down hill the whole time, the Prefab Road is what the player will be running on the entire time. It is just one transformed cube atm for the prototype. I'm currently attempting to load in another Road directly after it once i hit a certain point on the Road that already exists. After I get this working I will be dealing with ways to make it more efficient and adding that curve you see in most Endless Runners. As well the obstacle load in functionality.
     
  12. SirBumRush

    SirBumRush

    Joined:
    Apr 7, 2014
    Posts:
    5
    I'm open to this way of creating the game. Do you have any links of examples or any good tutorials that teach this method?
     
  13. SirBumRush

    SirBumRush

    Joined:
    Apr 7, 2014
    Posts:
    5
    Nice, I think I have a good understanding of what you're saying. I'm going to give a try, thanks m8.
     
  14. Vipsu

    Vipsu

    Joined:
    Oct 8, 2012
    Posts:
    88
    After some quick googling I found this nice little project made in Global Gamejam 2014
    http://globalgamejam.org/2014/games/gray-girl

    The game is open source so you can just download the project and play around with it. The source code is in english but the comments aren't but it looks pretty clear from a quick glance.
    https://github.com/amostajo/ggj14

    It's an 3D endless runner that uses the "treadmill mechanic" instead of moving the player

    Global game jam is an amazing event which produces a ton of good examples for many types of games. There are a lot of professionals in these events and you can learn a ton from their work, especially since the projects are small which makes it a lot easier to understand how the game actually works on a core level.
     
    Last edited: Oct 1, 2014
    SirBumRush likes this.
  15. SirBumRush

    SirBumRush

    Joined:
    Apr 7, 2014
    Posts:
    5
    Yeah I'm not sure if that will be an issue either. Something I need to test and figure out.
    Awesome man, your help is appreciated.