- Home /
[BEGINNER] Generating Terrain with Perlin noise flat and nothing happens ?
Hi
the Script below should make a cube, and then copy it while setting the depth according to the perlin noise, and always go +1 along both z and x axis. However, when I run the script, the cubes are all on the same heigth.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class terrainGen : MonoBehaviour { public terrainGen terrain; private GameObject cube; private int seed = 4864842; private float heigth;
// Use this for initialization
void Start () {
cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
editTerrain ();
heigth = 0.0f;
}
void editTerrain()
{
int xResolution = 50;
int zResolution = 50;
//float[,] heights;
for(int z=0; z <= zResolution ; z++)
{
for(int x=0; x <= xResolution ; x++)
{
float y = Mathf.PerlinNoise (heigth+seed, 0.0f);
Debug.Log (heigth);
heigth = heigth + 100f;
Instantiate(cube, new Vector3(x, y, z),Quaternion.identity);
}
}
}
}
Answer by AtGfx · Jun 12, 2017 at 08:18 AM
Hi !
Just call Mathf.PerlinNoise with a different seed. In your exemple it is always 4864842. You can use time for exemple as seed.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How to handle Perlin Noise ? 0 Answers
perlin noise terrain is spikey 0 Answers
How do i get the LocalSize of an object? 2 Answers
Clear gaps/cuts in trail renderer 0 Answers