I am currently working on a 3D Voxel Mining Game, using 6x6x6 blocks. I have the mining part down and have been trying to make cave generation for days yet, I do not know where to start whatsoever.
I want to make it so whenever the cave function is called, that 1 single (3D) cave is spawned upon request. However, have no clue how to do this because every single instance of these caves I’ve seen are math.noise usages which create multiple caves. Where do I start and how would I go upon making this?
This is an example of what I want it to do (obviously in 3D form instead of 2D though):
I am not exactly sure what you mean by “1 cave” but I assume you want the generator algorithm to fill an area with one big hole in it?
Most world generation algorithms try to fill a space. You might have better luck looking at maze generation if you want a start point and a ambiguous end point. Applying maze generation in 3D can be tricky though! Still you can start out with a “marching cube” that carves a path for you, a simple algorithm would be to start at the entrance and pick a random direction (up, down, left, right, but never backwards) delete that voxel and keep marching in that direction. This would make random winding tunnels but it would at least be connected. To build on our marching cube we add conditions like “never pick a direction that is empty” and tell it to prefer going left/right over up/down.
So would I just essentially make a cube in which moves in one of the 6 directions, excluding ones which right behind it and then make it move at random for a while and then end. That seems like a good idea but how would I adjust the thickness and then convert all affected blocks into my usedPositions table?
Not sure what “thickness” means in this context, I would assume you would always go block by block which should be standard size; 6x6x6 like you mentioned. I believe you would remove them from the usedPositions table, but I also do not know what you have created that for specifically.
Without a lot more context you will be on your own to explore the wide world of generative content!
oh! by thickness I was just referring to how wide a cave could possibly be when generated instead of it just being a shallow block line moving across randomly, also the game uses a usedPositions table to check if you can generate a block in the position or not, if it finds the position in the table, it renders it essentially as air and doesnt generate a block there