Procedural mesh is wavy and strange (diamond square algorithm)

Hey everyone!

so im working on generating a mesh with a diamond square and I decided to use procedural meshes, I cannot for the life of me figure out why I’m getting this wavy pattern with the mesh triangles.

i followed this video: https://www.youtube.com/watch?v=s2_K3dzXDoM&list=PLyL5ZNukfVqskz_OkMdrLamiYg1sITyic&index=2

but I didn’t set random heights, I used a decay factor so its supposed to taper the heights nicely. here is my problem and the mesh generation method. please let me know if Im doing something wrong or if it needs a smoothing filter or something

the wireframe looks good but when u zoom in use see the issue


Thank you!

(i took out the part with the vertex colors cause its not important)

void APCG::GenerateMesh()
{
for (int x = 0; x < GridSize; x++) {
for (int y = 0; y < GridSize; y++) {
FVector Vertex = FVector(xGridSpacing,yGridSpacing,HeightMap[x+yGridSize]);
MeshVertices.Add(Vertex);
// Add UV coordinates
UVs.Add(FVector2D((x
UVGridSpacing)/GridSize, (y*UVGridSpacing)/ (GridSize)));
//DrawDebugSphere(GetWorld(),Vertex, 20.0f,12, FColor::Green,true,-1.0f,0,2.0f);
}
}

for (int x = 0; x < GridSize-1; x++)
{
	for (int y = 0; y < GridSize-1; y++)
	{
		int BottomLeft = (y * GridSize) + x;        // Bottom-left vertex index
		int BottomRight = (y * GridSize) + (x + 1);  // Bottom-right vertex index
		int TopLeft = ((y + 1) * GridSize) + x;     // Top-left vertex index
		int TopRight = ((y + 1) * GridSize) + (x + 1); // Top-right vertex index

		// First triangle
		MeshTriangles.Add(BottomLeft);
		MeshTriangles.Add(BottomRight);
		MeshTriangles.Add(TopLeft);

		// Second triangle
		MeshTriangles.Add(BottomRight);
		MeshTriangles.Add(TopRight);
		MeshTriangles.Add(TopLeft);
	}
}

// Calculate normals (simple for now)
Normals.SetNum(MeshVertices.Num());
for (int32 i = 0; i < Normals.Num(); i++)
{
	Normals[i] = FVector(0, 0, 1); // Upward normals
}

// Tangents (optional, not used in this example)
Tangents.SetNum(MeshVertices.Num());
for (int32 i = 0; i < Tangents.Num(); i++) 
{
	Tangents[i] = FProcMeshTangent(0.0f, 1.0f, 0.0f); // Default tangent
}

// Create the mesh
ProceduralMesh->CreateMeshSection_LinearColor(0, MeshVertices, MeshTriangles, Normals, UVs, VertexColors, Tangents, true);
ProceduralMesh->SetCollisionProfileName(UCollisionProfile::BlockAllDynamic_ProfileName);
ProceduralMesh->SetMaterial(0, TerrainMaterial);