i want to calculate triangles using some sort of loop.

void calculatenoise()
{
for (int x = 0; x < xlenght; x++)
{
for (int y = 0; y < ylenght; y++)
{
for (int i = 0; i < Amplitudes.Length; i++)
{
generatednoise[x, y] += Amplitudes * Mathf.PerlinNoise(
Frequencies * x / xlenght * scale + xOffset, Frequencies * y / ylenght * scale + yOffset);
}
vertecies[vertecieindex] = new Vector3(x/xlenght, calculateheight(x, y), y/ylenght);
vertecieindex++;
}
}
}
float calculateheight(int x, int y)
{
return generatednoise[x, y];
}

You’ll need to provide way more information than that.


I’m assuming that you’re trying to procedurally generate a terrain using a heightmap for the position of the vertices. You need the triangles for the mesh, however, which aren’t complicated to calculate.


Think of the mesh as a plane, and construct small quads between every four vertices in the mesh. There is a video about this from Sebastian Lague, where he generates a mesh by calculating the triangles for a plane, with the vertices. See video here