I wanna know how to randomize perlin noise

I’m making a map out of blocks using perlin noise, the only problem is that the perlin noise doesn’t change, so the map always stays the same, and I’d like to know how to fix that, heres the code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GenerateInfiniteWorld : MonoBehaviour
{
public GameObject player;
public GameObject blockGameObject;

public int worldSizeX;
public int worldSizeZ;

public float noiseHeight;

public float gridOffset;
private Vector3 startPosition;

private Hashtable blockContainer = new Hashtable();

private List<Vector3> blockPositions = new List<Vector3>();

void Start()
{
    for (int x = -worldSizeX - 25; x < worldSizeX + 25; x++)
    {
        for(int z = -worldSizeZ - 25; z < worldSizeZ + 25; z++)
        {
            Vector3 pos = new Vector3(x * 1 + startPosition.x, generateNoise(x + xPlayerLocation, z + zPlayerLocation, 8f) * noiseHeight, z * 1 + startPosition.z);
            GameObject block = Instantiate(blockGameObject, pos, Quaternion.identity) as GameObject;
            blockContainer.Add(pos, block);
            blockPositions.Add(block.transform.position);
            block.transform.SetParent(this.transform);
        }
    }
}

private void Update()
{
    if(Mathf.Abs(xPlayerMove) >= 1 || Mathf.Abs(zPlayerMove) >= 1)
    {
        for (int x = -worldSizeX; x < worldSizeX; x++)
        {
            for (int z = -worldSizeZ; z < worldSizeZ; z++)
            {
                Vector3 pos = new Vector3(x * 1 + xPlayerLocation, generateNoise(x + xPlayerLocation, z + zPlayerLocation, 8f) * noiseHeight, z * 1 + zPlayerLocation);
                if (!blockContainer.ContainsKey(pos))
                {
                    GameObject block = Instantiate(blockGameObject, pos, Quaternion.identity) as GameObject;
                    blockContainer.Add(pos, block);
                    blockPositions.Add(block.transform.position);
                    block.transform.SetParent(this.transform);
                }
            }
        }
    }
}

public int xPlayerMove
{
    get
    {
        return (int)(player.transform.position.x - startPosition.x);
    }
}

public int zPlayerMove
{
    get
    {
        return (int)(player.transform.position.z - startPosition.z);
    }
}
public int xPlayerLocation
{
    get
    {
        return (int)Mathf.Floor(player.transform.position.x);
    }
}

public int zPlayerLocation
{
    get
    {
        return (int)Mathf.Floor(player.transform.position.z);
    }
}

private Vector3 ObjectSpawnLocation()
{
    int rndIndex = Random.Range(0, blockPositions.Count);

    Vector3 newPos = new Vector3(
        blockPositions[rndIndex].x,
        blockPositions[rndIndex].y + 0.5f,
        blockPositions[rndIndex].z
        );
    blockPositions.RemoveAt(rndIndex);
    return newPos;
}
private Vector3 ObjectSpawnLocation2()
{
    int rndIndex = blockPositions.Count / 2;

    Vector3 newPos = new Vector3(
        blockPositions[rndIndex].x,
        blockPositions[rndIndex].y,
        blockPositions[worldSizeX / 2].z
        );
    blockPositions.RemoveAt(rndIndex);
    return newPos;
}
private Vector3 ObjectSpawnLocation3()
{
    int rndIndex = Random.Range(0, blockPositions.Count);

    Vector3 newPos = new Vector3(
        blockPositions[rndIndex].x,
        blockPositions[rndIndex].y + 0.5f,
        blockPositions[rndIndex].z
        ) ;
    blockPositions.RemoveAt(rndIndex);
    return newPos;
}

private float generateNoise(int x, int z, float detailScale)
 {
    float xNoise = (x + this.transform.position.x) / detailScale;
    float zNoise = (z + this.transform.position.y) / detailScale;

    return Mathf.PerlinNoise(xNoise, zNoise);
 }
}

Perlin noise is a procedural texture primitive, a type of gradient noise used by visual effects artists to increase the appearance of realism in computer graphics. The function has a pseudo-random appearance, yet all of its visual details are the same size.

greatpeople

Use offsets. Add a random value between -10000 and 10000 to your perlin noise x and y values before you generate a point. However, these random values need to be initialized once in a start function for example. Don’t randomize them every time you sample a point.


The offsets can also be kept predictable by using a seed value for your random number generator. For example:

public string Seed;

public int OffsetX;
public int OffsetY;

void Start()
{
     var rand = new System.Random(Seed.GetHashCode());

     OffsetX = rand.Next(-10000, 10000);
     OffsetY = rand.Next(-10000, 10000);
}