for循环不是从零开始

For loop not starting from zero

我正在尝试将生物群系系统实施到程序地形生成系统中。我这样做是为了让每个地形块的高度乘数根据它所在的生物群系而变化,但这会导致玩家能够进入两个生物群落相遇的地图下方。我试图使每个块的边缘高度为 0,以便它们正确连接。问题是,for 循环似乎不是从 0 开始的。我曾经将包含 x <= 8 的 if 语句设为 x == 0,但网格不会发生任何变化。

for (int y = 0; y < borderedSize; y += meshSimplificationIncrement) {
    for (int x = 0; x < borderedSize; x += meshSimplificationIncrement) {
        float height;
        if (x <= 8 || x >= 233) {
            height = 5.0f;
            //Debug.Log(height);
            //Debug.Log("x" + x);
        } else if (y <= 8 || y >= 233) {
            height = 5.0f;
            //Debug.Log(height);
            //Debug.Log("y" + y);
        } else if (y <= 32 || y >= 225) {
            height = heightCurve.Evaluate(heightMap[x, y]) * heightMultiplier;
            height = height / 1.5f;
        } else if (x <= 32 || x >= 225) {
            height = heightCurve.Evaluate(heightMap[x, y]) * heightMultiplier;
            height = height / 1.5f;
        } else {
            height = heightCurve.Evaluate(heightMap[x, y]) * heightMultiplier;
        }
        int vertexIndex = vertexIndicesMap[x, y];
        Vector2 percent = new Vector2((x - meshSimplificationIncrement) / (float)meshSize, (y - meshSimplificationIncrement) / (float)meshSize);
        Vector3 vertexPosition = new Vector3(topLeftX + percent.x * meshSizeUnsimplified, height, topLeftZ - percent.y * meshSizeUnsimplified);

        meshData.AddVertex(vertexPosition, percent, vertexIndex);

        if (x < borderedSize - 1 && y < borderedSize - 1) {
            int a = vertexIndicesMap[x, y];
            int b = vertexIndicesMap[x + meshSimplificationIncrement, y];
            int c = vertexIndicesMap[x, y + meshSimplificationIncrement];
            int d = vertexIndicesMap[x + meshSimplificationIncrement, y + meshSimplificationIncrement];
            meshData.AddTriangle(a, d, c);
            meshData.AddTriangle(d, a, b);
        }

        vertexIndex++;
    }
}

相信我,循环确实从 0 开始。

我会创建一个在边缘下降到 0 的斜坡。

const int rampSize = 32;

for (int y = 0; y < borderedSize; y += meshSimplificationIncrement)
{
    for (int x = 0; x < borderedSize; x += meshSimplificationIncrement)
    {
        float height = heightCurve.Evaluate(heightMap[x, y]) * heightMultiplier;
        int min = Math.Min(x, y);
        int max = Math.Max(x, y);
        int borderDist = Math.Min(min, borderedSize - max);
        if (borderDist < rampSize) {
            height = height * (float)borderDist / rampSize;
        }
        ...
    }
}

这会创建一个看起来像截棱锥的坡道。