Need advice on cubic terrain generation

UskazdUskazd Posts: 5Member
in 3D

My brother and I are working on our first game together, however because he currently needs to focus on college we’re putting that project on hiatus. Since he’s the programmer I’m basically stuck with what I can still add, other than notes and the occasional 2D sprite.
I decided that I wanted to start working on one of the other games I thought of (a first-person city builder/strategy game), so I learn at the very least learn some coding language (since most of my programming knowledge comes from modding CK2) and we can have a foundation to work of when we start working on that game. Since Godot is open-source and allows modules with diffrent coding languages it seems like a good engine to work with.
And yes, I know that I’m putting a lot on my plate by starting with something like this. But I’m know for taking on difficult tasks and while it frustrates me when I’m blocked, like now, the rush/feeling of accomplishment you get when you finally figure it out is worth the trouble.

I’m aiming to build a prototype that allows me to:

  • Generate a world with save and load functions
  • Terrain that can be destroyed and placed
  • Crafting items with a simple recipe list
  • AI that can gather items and craft based on needs
  • Basic combat, with AI that can attack
  • Control where certain AI move with command buttons

I’ve already created most of the menus and GUI, but these are the easiest to create. As it stands I’m stuck at terrain generation. I basically need to set up a Minecraft-like terrain (cubic generated by seed and destructible) so I can start working on the other aspects.

A quick overview of what I’m trying to learn at the moment:

  • Generate terrain from OpenSimplexNoise
    o Be able to put the seed in a menu before starting
    o Save and load a world in a menu

  • Make the terrain destructible

  • Texture the different sides of a cube using separate texture files
    o Example:
     grass_block: grass_top.png, grass_side.png, dirt.png
     dirt_block = dirt.png
    Additional bonuses if I could learn them:

  • Prepare the foundation for basic multiplayer

  • How to add gravity to blocks

I’ve tried out several (YouTube) tutorials on terrain generation, but they all seem to end up in flops. I know about Zylann’s voxel engine but I want to learn/understand how terrain generation functions so that during development I can modify the code how I see fit without accidently destroying everything in the process.

From what I’ve learned from my failures I figure that the best way to generate terrain would be to:
1. Create a CubeMesh which changes texture and elements depending on the block_type associated with it
2. Create a MultiMesh from those cubes which act as chunks.
3. Create a GridMap that places the chunks next to each other

So my main question is; Does anyone have advice on which tutorials or documentation I can use to work on terrain gen?

Comments

  • MegalomaniakMegalomaniak Posts: 2,785Admin

    I think @Zylann had a plugin for generating such terrain but not sure if it was up to date/compatible with the current version of godot. Might be worth exploring.

  • UskazdUskazd Posts: 5Member

    As I said, I know of the plugin but it's going to make it more difficult for me to understand the code I need to make and use in the long run if I just use a premade.

    I learn best by just doing it. Even when I follow a guide on how to make terrain gen I can still learn how everything is connected by repeating the proces step by step.

  • TwistedTwiglegTwistedTwigleg Posts: 2,873Admin

    Well, its probably a bit out of date, but I have a tutorial on a simple voxel terrain system in Godot on RandomMomentania. It doesn't cover generating a world using noise however, and its performance is limited by the use of the SurfaceTool, but it may help as a starting point or reference for making your own system.

  • UskazdUskazd Posts: 5Member

    Hmm, it can definitly help with setting up the break/build and textureing facets. Thanks!

  • komposter64komposter64 Posts: 3Member

    Generating a simple heightmap for your world with OpenSimplexNoise probably isn't too complex. I'd recommend a noise with at least 3 octaves and a high period. You can fiddle around with the other parameters until you get a result that feels right. Lacunarity and Persistence influence how much impact each octave has in the final value. More octaves give you more variation and a high period stretches variations over a larger area, giving you smooth hills. Your can then represent your world as a 2D grid (x,z), where each cell of the grid represents the hight at that point. Then you can just sample the noise by using get_noise_2d(x,z) for each grid cell to get a random hight value. When converting the hightmap to 3D you would then check each's block 3D position (x,y,z) against the height in the heightmap at (x,z). Every block below (y<=height) that hight would be solid, everything above (y>height) would be emtpy. Since get_noise_2d gives you a value between -1 and 1, you might have to scale that to your min/max world height.

  • UskazdUskazd Posts: 5Member

    Ok, I think I got a decent grip on how I want to implement the worldgen and what I need for it.

    I placed my notes in the added GDscript.

    So again, any criticism is welcome.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file