I’m making a game where the player moves through an endless scrolling 2D world. Currently, I want the terrain to represent a sine wave, as shown in the provided illustration.

How should I setup my terrain scene to generate this terrain with collision? Or should the terrain generation be in the main game scene? If the later, what node structure should I use for my terrain?

  • Luccus@feddit.org
    link
    fedilink
    arrow-up
    7
    ·
    8 days ago

    I’d probably try to do this programatically. A collisionshape/-volume that’s calculated on-CPU and a small shader reimplementing the same shape / sine wave just visually on the GPU.

    This should work if:

    • the algorythm is not too complex/heavy
    • you don’t want to hand-place objects
    • you like working with fractals and similar math

    You can also adopt the wandering clipmap solution, if the terrain will not be convex.

  • burghler@sh.itjust.works
    link
    fedilink
    arrow-up
    3
    ·
    8 days ago

    Decide on a resolution and then connect those verts (points on the wave) and give everything below it a material. Maybe user a mask for that.

    For node structure it doesn’t really matter, if it’s gonna persist then give it its own scene. Everything will live under the game node anyway. Structure matters only when you have nodes talking to eachother, and creating and deleting. For the sake of maintaining references.

    This game shouldn’t have many nodes anyway so don’t stress it.

    • Sanctus@anarchist.nexus
      link
      fedilink
      English
      arrow-up
      2
      ·
      8 days ago

      It might be interesting to make the node its own scene if only to use it as a “plug in” to change the generation. Then you could make different generators that you pop in and out during play. But tbh you could probably achieve that without a separate scene by exposing the generation params in the inspector.