Search Unity

How to make traffic behave as it does in "Frogger?" (3D)

Discussion in 'Scripting' started by Zuon94, Nov 9, 2014.

  1. Zuon94

    Zuon94

    Joined:
    Aug 4, 2011
    Posts:
    11
    So, in my game, I have a level that starts out like Frogger, with lanes of traffic at the start, followed by a river you have to cross by jumping on row boats. My question is, how would I make the traffic and boats seamlessly scroll in one direction, endlessly, while being on the road/water from the very beginning (instead of driving out of the tunnel onto an empty road at the start of the level) and keeping each vehicle's colliders intact?

    I'm very new to coding (but I'm still learning), and something like this is a little big for me to figure out in a reasonable time without getting frustrated. I am asking here though, because while I would normally wait until gaining enough knowledge to do it myself, I don't want to chance giving up on another one of my projects, as I've already got three levels and a tutorial done, previously.
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Just place all the cars/boats on the road/river where you want them to start, in the level editor. Include a few outside the visible part of the scene, i.e., a little off the screen to one side, and not yet entered on the other.

    Now, in the movement script you're going to write for these things, you simply check to see if they've gone entirely offscreen (plus whatever extra margin you want to allow), and if so, reset their position to the other side — the entrance side, plus some margin in that direction.

    That's it. Now they keep cycling on through indefinitely. If you're worried about the player noticing the pattern, just make your margins wider and add more offscreen cars/boats.

    Cheers,
    - Joe
     
  3. Zuon94

    Zuon94

    Joined:
    Aug 4, 2011
    Posts:
    11
    Thank you very much, I'll see what I can come up with. Be aware though, that I may come back here and ask for example code if I can't entirely figure it out by myself. ^^ But I'll see what I can do. Thanks again for your help.