Difficulty with Perlin Noise based Terrain Generation

First off I know that this sort of question has been asked 101 times already on here, but I’ve honestly read a good 80% of them, and none offer me anymore information than I currently have.

I’m prototyping out a game which requires a really simple low-res terrain, and I eventually stumbled onto a few Perlin Noice tutorials. This is the function I have currently:

public void GenerateTerrain(float tileSize){

	TerrainData TD = selfTerrain.terrainData;
	//Higher = More Hills/Mountains
	float HM = Random.Range(0,10);
	//Lower = Higher Mountains/Hills
	float divRange = Random.Range(12,25);
	int height = TD.heightmapHeight;
	int width = TD.heightmapWidth;

	float[,] heights =  new float[width,height];

	for(int i = 0; i < width; i++){
		for(int k = 0; k < height; k++){
			heights[i,k] = Mathf.PerlinNoise((i/width) * tileSize, (k/height) * tileSize) / divRange;
	Debug.Log("DivRange: " + divRange + " , " + "HTiling: " + HM);

but instead of making me some nice ripply terrain it applies the same height to the whole terrain object, essentially just moving it up and down. The happens event when I use Random.Range to just put a random height onto every location in the heightmap.

If its something stupid, please don’t rub it in, I’ve been up for probably a bit too long.

Cheers in Advance

Actually the problem is that maths for integers and floats work differently. Dividing int by int will not get you a float you need. Keep it in mind next time.

heights[i,k] = Mathf.PerlinNoise((1f*i/width) * tileSize, (1f*k/height) * tileSize) / divRange;

This will work like expected. Multiplying and int by 1f (float 1) will make it a float and you will get your expected result. Enjoy your noises! :slight_smile:

I’m assuming tileSize is an int here, but the problem is likely that Perlin Noise doesn’t work when it’s input is a perfect whole number, an integer. Try multiplying your x and y by some random float value.