Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Infinite scrolling terrain

Discussion in 'Scripting' started by KasunL, Sep 30, 2021.

  1. KasunL

    KasunL

    Joined:
    Apr 19, 2015
    Posts:
    64
    Hi.

    I currently have this small aircraft/spacecraft game. I want to make an endlessly scrolling terrain to create the illusion of flight for the craft. Any pointers to how to get started please? Tnx.

    Current state:

     
    Last edited: Oct 1, 2021
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,741
    Mesh generation is not a lesson for the faint of heart, and making it efficient even harder.

    Truthfully, I'd recommend grabbing something from the Asset Store for this - there's very little to be gained by writing your own, as it's not something that interacts deeply with the rest of your game's systems, and an asset is more likely to be robust, performant, and well-tested. There's at least 2 free ones and countless better paid ones up there.
     
    exiguous and KasunL like this.
  3. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    This is true. But fortunately we can stand on the shoulders of giants (figuratively speaking). There is plenty of material to be found on the interweb. Some examples:
    https://github.com/Unity-Technologies/MeshApiExamples
    https://catlikecoding.com/unity/tutorials/
    https://www.raywenderlich.com/7880445-unity-job-system-and-burst-compiler-getting-started
    https://forum.unity.com/threads/infinite-terrain-free-project-source.68807/#post-3827623

    I just would have some "patches" or "chunks" which are placed around the player and when the player leaves an area it is placed in front of him again (reused) and just populated with new height values (like the OP of the last link which is 404 but you could try to find it with internet archive).
    Most basic examples just create a grid of quads, this you fill with noise values for some heights and apply some colors (potentially via shaders). And you should be done. Given that you aim for a lowpoly style look. Highly realistic terrain is better done by specialized tools like Gaia or similar. It's just the question if you want to spend the time to learn this stuff or spend the money to have it ready.
     
    KasunL likes this.
  4. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    I think you need to maybe be more specific in exactly what you're trying to do, how complicated is your game, is it it more arcade and you want scrolling terrain to go by? Or is it a full open world you're thinking of? Depending on the answer it might be easier than people are making out.
     
    KasunL likes this.
  5. KasunL

    KasunL

    Joined:
    Apr 19, 2015
    Posts:
    64
    Thanks for the replies!

    It's a simple game. The craft won't leave the small boundary it was put in. So I'm not trying to spawn terrains while I flyby. What I want is an endlessly scrolling 3D background / terrain, so it would create the illusion of flight. And, No it's not an open world. More in the arcade side.
     
  6. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    You could look into parallax scrolling in that case but just have the effect on each side you want it being viewed in the cockpit. Even with the possibility of a complicated mesh generation a technique used to give the impression of a bigger world is when games developers make 'cells' instantiate before hand when you're moving forward and you could make use of a perlin noise generator to make something more fancy. After that, if you're not wanting to do anything complicated like spawning enemies on the terrain since it looks like a space sim it's just a matter of them having instantiate at random points as you go forward.

    Don't know why people are making it out that it's too complicated, sure if you're a complete noob yes, but if you take the time to study it you can still learn it no problem. There are multiple techniques you can use for mesh generation, it doesn't have to be all about generating triangles from scratch.
     
    KasunL likes this.