[英]Getting weird results from terrain generation sys using 2D Perlin Noise
我正在尝试在 Unity 中创建一个地形生成系统,类似于 Minecraft 的,但使用 Unity 的 Perlin Noise function(所以只有 2D 噪声)。
所以我有一个vector2int
的块,它的 vector2int 是 position(就像,如果 x & z = 0,那么里面的块在世界坐标中是从 0 到 16)。
这就是我试图生成一个块的高度 map 的方式:
public void generate(float scale) {
GameObject root = new GameObject("Root");
// this.z & this.x are the chunk coordinates, size is 16
for(int z = this.z * size; z < (this.z + size); ++z) {
for (int x = this.x * size; x < (this.x + size); ++x) {
float[] coord = new float[2] { (float)x / size * scale,
(float)z / size * scale };
Debug.LogFormat("<color='blue'>Perlin coords |</color> x: {0}; y: {1}", coord[0], coord[1]);
float value = Mathf.PerlinNoise(coord[0], coord[1]);
// temporary
GameObject Cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
Cube.transform.position = new Vector3(x, value, z);
Cube.transform.parent = root.transform;
}
}
return;
}
结果……不好。 你自己看:
我能做些什么?
它看起来不错,看起来只是在 y 变换上变形。
float value = Mathf.PerlinNoise(coord[0], coord[1]);
这会给你带来问题,我不确定 coord[0] 和 coord[1] 是什么,但 Mathf.PerlinNoise 会返回 coord[0] 和 coord[1] 之间的随机浮点数,所以随机浮点数永远不会能够生产对齐良好的瓷砖。
最好做类似的事情
int numTilesHigh = Random.Range(0,15);
for (int i = 0; i < numTilesHigh; i++) {
GameObject Cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
Cube.transform.position = new Vector3(x, <cube height> * i, z);
Cube.transform.parent = root.transform;
}
ps 我有点喜欢你的屏幕截图,不是以我的世界的方式,但它看起来很酷:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.