使用时注意的几点:
1. 乘以unkownCoef之后(如我默认是0.05f,就把 j = 1,2,3变成 j = 0.05,0.10, 0.15...) 这样perlin()的 j 参数之间差别的就不大,k参数同理,这样就比较丝滑)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BerlinNoiseTest : MonoBehaviour
{
public GameObject obj;
List cubes = new List();
// Start is called before the first frame update
void Start()
{
for (int i = 0; i < 20; i++)
{
for (int j = 0; j < 20; j++)
{
GameObject o = Instantiate(obj);
o.transform.position = Vector3.zero;
o.transform.position = new Vector3(i, 0, j);
cubes.Add(o);
}
}
}
public float offSet = 1;
[SerializeField]
float timer = 0;
public float unkownCoef = 0.05f;
void Update()
{
timer += Time.deltaTime;
for (int i = 0; i < cubes.Count; i++)
{
float j = i % 20;
float k = i / 20;
float yPos = 5 * Mathf.PerlinNoise(j * unkownCoef + timer * offSet, k * unkownCoef + timer * offSet);
cubes[i].transform.position = new Vector3(cubes[i].transform.position.x, yPos, cubes[i].transform.position.z);
}
}
}



