2D: Node structure for generating sine wave terrain?

3 months ago by AstroLightz to c/godot

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 7 points 3 months 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.

path: 0 24668449, hotness: undefined, score: 7, children: 0
Burghler 3 points 3 months 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.

path: 0 24667505, hotness: undefined, score: 3, children: 1
Sanctus 2 points 3 months 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.

path: 0 24667505 24667844, hotness: undefined, score: 2, children: 0
godot
godot

@programming.dev

login for more options
7983
1193
558

Welcome to the programming.dev Godot community!

This is a place where you can discuss about anything relating to the Godot game engine. Feel free to ask questions, post tutorials, show off your godot game, etc.

Make sure to follow the Godot CoC while chatting

We have a matrix room that can be used for chatting with other members of the community here

Links

Other Communities

Rules

  • Posts need to be in english
  • Posts with explicit content must be tagged with nsfw
  • We do not condone harassment inside the community as well as trolling or equivalent behaviour
  • Do not post illegal materials or post things encouraging actions such as pirating games

We have a four strike system in this community where you get warned the first time you break a rule, then given a week ban, then given a year ban, then a permanent ban. Certain actions may bypass this and go straight to permanent ban if severe enough and done with malicious intent

Wormhole

!roguelikedev@programming.dev

Credits

  • The icon is a modified version of the official godot engine logo (changing the colors to a gradient and black background)
  • The banner is from Godot Design

go to feed...