How to create Voxel Terrain Generation in Unity











up vote
1
down vote

favorite












That is the code that I am using for generating the terrain. But I can't manage to use the 2D Perlin Noise, it is creating a lot of no-needed blocks and does not look quite quadratic.



As a GrassCube I am using the default unity 3D Cube. I Will add texture later



Terrain picture



enter image description here



public GameObject GrassCube;
public GameObject RockCube;
public GameObject DirtCube;

void Start ()
{
CreateCube(16, 16, 16);
}

public void CreateCube(int sizeX, int sizeY, int sizeZ)
{
for (int x = 0; x < sizeX; x++)
{
for (int y = 0; y < sizeY; y++)
{
for (int z = 0; z < sizeZ; z++)
{
float PerlinNoise = Mathf.PerlinNoise(x * 0.2f, z * 0.2f) * 3;

GrassCube = Instantiate(GrassCube, new Vector3(x, PerlinNoise, z), Quaternion.identity);
GrassCube.name = "Cube:" + x + ", " + y + ", " + z;
}
}
}
}









share|improve this question




















  • 1




    Hi, I am afraid I am not clear what problem you are trying to solve, can you expand on what issues you are having?
    – Loofer
    Nov 11 at 15:43










  • I mean you are looping 3 dimensionally for what appears to be a 2 dimension problem, and since your "y" of your cubes comes from perlin noise I think it is safe to remove that loop.
    – Eddge
    Nov 11 at 17:38










  • I want to create voxel world like this one using 2D Perlin Noise Voxel world
    – MadForLife
    Nov 11 at 19:26












  • Nevermind I managed to fix it now I need to add more depth and mountains to the world WorldGen
    – MadForLife
    Nov 12 at 6:55















up vote
1
down vote

favorite












That is the code that I am using for generating the terrain. But I can't manage to use the 2D Perlin Noise, it is creating a lot of no-needed blocks and does not look quite quadratic.



As a GrassCube I am using the default unity 3D Cube. I Will add texture later



Terrain picture



enter image description here



public GameObject GrassCube;
public GameObject RockCube;
public GameObject DirtCube;

void Start ()
{
CreateCube(16, 16, 16);
}

public void CreateCube(int sizeX, int sizeY, int sizeZ)
{
for (int x = 0; x < sizeX; x++)
{
for (int y = 0; y < sizeY; y++)
{
for (int z = 0; z < sizeZ; z++)
{
float PerlinNoise = Mathf.PerlinNoise(x * 0.2f, z * 0.2f) * 3;

GrassCube = Instantiate(GrassCube, new Vector3(x, PerlinNoise, z), Quaternion.identity);
GrassCube.name = "Cube:" + x + ", " + y + ", " + z;
}
}
}
}









share|improve this question




















  • 1




    Hi, I am afraid I am not clear what problem you are trying to solve, can you expand on what issues you are having?
    – Loofer
    Nov 11 at 15:43










  • I mean you are looping 3 dimensionally for what appears to be a 2 dimension problem, and since your "y" of your cubes comes from perlin noise I think it is safe to remove that loop.
    – Eddge
    Nov 11 at 17:38










  • I want to create voxel world like this one using 2D Perlin Noise Voxel world
    – MadForLife
    Nov 11 at 19:26












  • Nevermind I managed to fix it now I need to add more depth and mountains to the world WorldGen
    – MadForLife
    Nov 12 at 6:55













up vote
1
down vote

favorite









up vote
1
down vote

favorite











That is the code that I am using for generating the terrain. But I can't manage to use the 2D Perlin Noise, it is creating a lot of no-needed blocks and does not look quite quadratic.



As a GrassCube I am using the default unity 3D Cube. I Will add texture later



Terrain picture



enter image description here



public GameObject GrassCube;
public GameObject RockCube;
public GameObject DirtCube;

void Start ()
{
CreateCube(16, 16, 16);
}

public void CreateCube(int sizeX, int sizeY, int sizeZ)
{
for (int x = 0; x < sizeX; x++)
{
for (int y = 0; y < sizeY; y++)
{
for (int z = 0; z < sizeZ; z++)
{
float PerlinNoise = Mathf.PerlinNoise(x * 0.2f, z * 0.2f) * 3;

GrassCube = Instantiate(GrassCube, new Vector3(x, PerlinNoise, z), Quaternion.identity);
GrassCube.name = "Cube:" + x + ", " + y + ", " + z;
}
}
}
}









share|improve this question















That is the code that I am using for generating the terrain. But I can't manage to use the 2D Perlin Noise, it is creating a lot of no-needed blocks and does not look quite quadratic.



As a GrassCube I am using the default unity 3D Cube. I Will add texture later



Terrain picture



enter image description here



public GameObject GrassCube;
public GameObject RockCube;
public GameObject DirtCube;

void Start ()
{
CreateCube(16, 16, 16);
}

public void CreateCube(int sizeX, int sizeY, int sizeZ)
{
for (int x = 0; x < sizeX; x++)
{
for (int y = 0; y < sizeY; y++)
{
for (int z = 0; z < sizeZ; z++)
{
float PerlinNoise = Mathf.PerlinNoise(x * 0.2f, z * 0.2f) * 3;

GrassCube = Instantiate(GrassCube, new Vector3(x, PerlinNoise, z), Quaternion.identity);
GrassCube.name = "Cube:" + x + ", " + y + ", " + z;
}
}
}
}






c# unity3d terrain perlin-noise voxel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 15:59









Loofer

4,51354489




4,51354489










asked Nov 10 at 22:36









MadForLife

63




63








  • 1




    Hi, I am afraid I am not clear what problem you are trying to solve, can you expand on what issues you are having?
    – Loofer
    Nov 11 at 15:43










  • I mean you are looping 3 dimensionally for what appears to be a 2 dimension problem, and since your "y" of your cubes comes from perlin noise I think it is safe to remove that loop.
    – Eddge
    Nov 11 at 17:38










  • I want to create voxel world like this one using 2D Perlin Noise Voxel world
    – MadForLife
    Nov 11 at 19:26












  • Nevermind I managed to fix it now I need to add more depth and mountains to the world WorldGen
    – MadForLife
    Nov 12 at 6:55














  • 1




    Hi, I am afraid I am not clear what problem you are trying to solve, can you expand on what issues you are having?
    – Loofer
    Nov 11 at 15:43










  • I mean you are looping 3 dimensionally for what appears to be a 2 dimension problem, and since your "y" of your cubes comes from perlin noise I think it is safe to remove that loop.
    – Eddge
    Nov 11 at 17:38










  • I want to create voxel world like this one using 2D Perlin Noise Voxel world
    – MadForLife
    Nov 11 at 19:26












  • Nevermind I managed to fix it now I need to add more depth and mountains to the world WorldGen
    – MadForLife
    Nov 12 at 6:55








1




1




Hi, I am afraid I am not clear what problem you are trying to solve, can you expand on what issues you are having?
– Loofer
Nov 11 at 15:43




Hi, I am afraid I am not clear what problem you are trying to solve, can you expand on what issues you are having?
– Loofer
Nov 11 at 15:43












I mean you are looping 3 dimensionally for what appears to be a 2 dimension problem, and since your "y" of your cubes comes from perlin noise I think it is safe to remove that loop.
– Eddge
Nov 11 at 17:38




I mean you are looping 3 dimensionally for what appears to be a 2 dimension problem, and since your "y" of your cubes comes from perlin noise I think it is safe to remove that loop.
– Eddge
Nov 11 at 17:38












I want to create voxel world like this one using 2D Perlin Noise Voxel world
– MadForLife
Nov 11 at 19:26






I want to create voxel world like this one using 2D Perlin Noise Voxel world
– MadForLife
Nov 11 at 19:26














Nevermind I managed to fix it now I need to add more depth and mountains to the world WorldGen
– MadForLife
Nov 12 at 6:55




Nevermind I managed to fix it now I need to add more depth and mountains to the world WorldGen
– MadForLife
Nov 12 at 6:55

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244112%2fhow-to-create-voxel-terrain-generation-in-unity%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53244112%2fhow-to-create-voxel-terrain-generation-in-unity%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues