# Procedural generation with minerals and mining with caves(need guidance)

Discussion in 'Scripting' started by Capnarchie, Jan 3, 2017.

1. ### Capnarchie

Joined:
Nov 1, 2015
Posts:
62
Hello, i would like to make a terrain system like space engineers or astroneer(without the low poly count).
But i honestly have no clue how to make such a system, I would like to see in my system; mining terrain like in space engineers so im guessing it has to do something with marching cubes. but the biggest problem might be generating the resources in the terrain/on the terrain so i could have them as materials to craft just like minecraft and have caves. I have tested cubiquity and thats pretty much what i expect from the mining but it didnt procedurally generate and it was without materials. I'm not a beginner coder im somewhere inbetween intermediate in my opinion.

I am very grateful for any guidance/assistance thanks.

EDIT: and is there a way possible to make it into a planet aswell? i think unity doesnt support that though just a question.

Last edited: Jan 3, 2017
2. ### gorbit99

Joined:
Jul 14, 2015
Posts:
1,175
You can generate a terrain with either perlin noise or some other algorithm
And hey, it just so happens, that I wrote a tutorial few days ago, that creates a Diamond-Square Algorithm, that works well with terrain generation (Shameless self-advertising)

The most common way of dealing with ores and caves (minecraft does it as well) is having a 3d perlin noise (Unity doesn't support that, so you have to download a library yourself. I would suggest a C# implementation of LibNoise, that works great and it has so many different noisetypes, that you can experiment with as well) After this you check the values of this noise and if it's let's say below 0.2 you generate a cave or if it's between 0.5 and 0.6 that's copper, and so on.

A game like space engineers is called a voxel game, where every block is a single value in a 3d coordinate system. You can visualize these values in multiple ways:
You can have cubes like in minecraft
Or you can have marching cubes. And again in a few days a tutorial about marching cubes algorithm will be on my site as well, so stay tuned for that (Shameless self advertising again, I will stop now, sorry)

It's hard, but you can obviously. You just need to map the values of the noises onto a sphere, I'm sure there are a lot of tutorials online

Capnarchie and xjjon like this.
3. ### xjjon

Joined:
Apr 15, 2016
Posts:
184
Wouldn't you be able to generate ores/caves with 2d perlin noise as a height map? Or do you map the 3d noise onto the height map as density?

Also thanks for sharing your blog post, bookmarked to read after work.

4. ### Vancete

Joined:
May 3, 2010
Posts:
180
There's an awesome (and cheap) noise generator called FastNoise on the Store.

I bought it some weeks ago and developed my own 'infinite procedural realistic terrain generator' (what a long name).

And hey, wasn't that hard after all. Feel free to ask.

5. ### gorbit99

Joined:
Jul 14, 2015
Posts:
1,175
I still think libnoise is better, mainly because it's free and even the C# port is really fast (and noise way more noise types than fastNoise)

6. ### Vancete

Joined:
May 3, 2010
Posts:
180
Didn't tested that lib, just saying one that worked REALLY nice and easily. I'll dig into that.

7. ### Capnarchie

Joined:
Nov 1, 2015
Posts:
62
So lets say that i'm choosing to make a spherical voxel world. Assuming that space engineers doesnt use trickery to make it look like a planet. I would be able to create it with libnoise?

8. ### gorbit99

Joined:
Jul 14, 2015
Posts:
1,175
Yes, you could most likely

9. ### Capnarchie

Joined:
Nov 1, 2015
Posts:
62
But how would I do the terrain mining part? And generate the caves on terrain that are part of a mountain. I don't know I'm so curious and don't know nothing about this stuff.

Edit: Also does libnoise support smooth voxels? I wouldn't just want to make a spherical minecraft.

Last edited: Jan 5, 2017
10. ### gorbit99

Joined:
Jul 14, 2015
Posts:
1,175
Libnoise only generates a noise, the voxel part is done by you
And I never ever done a truly spherical world, this is something you have to test

11. ### Capnarchie

Joined:
Nov 1, 2015
Posts:
62
i just want it to look like a planet and planets arent perfectly spherical. and how would i do the voxel part?

unityunity