- Home /
Question by
Theacesofspades · Sep 06, 2015 at 06:21 PM ·
terrainintgenerationperlin noise
How can i use perlin noise to create better world?
I am making a game which uses blocks as the terrain. I am new to using perlin noise and I am not sure how to alter the terrain better than how i have it now.
The code I am using is:
void GenerateTerrain ()
{
data = new int[worldX,worldY,worldZ];
for (int x=0; x<worldX; x++)
{
for (int z=0; z<worldZ; z++)
{
int dirt = Noise(x,z, smoothStone,stoneHeightScale,stoneExponent);
dirt += Mathf.RoundToInt(stoneAddition);
int grass = Noise(x,z, smoothGrass,grassHeightScale,grassExponent);
grass += Mathf.RoundToInt(grassAddition);
for (int y=0; y<worldY; y++)
{
if (y == grass)
{
data[x, y, z] = 1;
}
if(y < grass)
{
data[x, y, z] = 2;
}
if(y < dirt)
{
data[x, y, z] = 3;
}
}
}
}
}
int Noise (int x, int z, float scale, float mag, float exp)
{
return (int) (Mathf.Pow ((Mathf.PerlinNoise(x/scale,z/scale)*mag),(exp) ));
}
Where:
// Air = 0
// Grass = 1
// Dirt = 2
// Stone = 3
// Sand = 4
// Water = 5
How can I use perlin noise to make my terrain better? Such as creating lakes, beaches, forests, caves, canyons?
Comment
You can apply perlin noise several times, each time with a smaller resolution, which will make our terrain more randomized and mask the obvious perlin noise effect.
Your answer
Follow this Question
Related Questions
Make a high poly count plane with code 0 Answers
2D Efficient Realtime Terrain Generation 0 Answers
3d Perlin Noise? 3 Answers
Terrain help 0 Answers
Perlin Noise for 3d Voxel Terrain 1 Answer