I’ve got a flatshaded mesh (no shared vertices). At runtime i flatten the triangles by moving the triangles vertices Y- value to all be the same. However when i do so the neighboring triangles will be disconnected from the flattened triangles. One way to fix this is by moving the neighboring overlapping vertices to the same Y-value around it. But this distorts already flattened triangles if the new flattened area is at a different Y-value beside the previously flattened area.

So i would like to connect the overlapping vertices with triangles but im not sure how to do so?

the mesh-script is created from Sebastian Lague’s Procedural terrain generation tutorial.

The red lines is where i want new triangle faces

The 2 triangles in the square are flattened out

```
using System.Collections;
using UnityEngine;
public class AlterMesh : MonoBehaviour
{
public MeshFilter meshFilter;
public MeshCollider meshCollider;
public Mesh mesh;
Vector3[] vertices;
int[] triangles;
int[] newTriangles;
// Use this for initialization
void Start()
{
meshCollider = this.GetComponent<MeshCollider>();
meshFilter = this.GetComponent<MeshFilter>();
mesh = meshFilter.mesh;
vertices = mesh.vertices;
triangles = mesh.triangles;
newTriangles = new int[triangles.Length*2];
AddTriangles();
}
// Update is called once per frame
void Update()
{
}
public void AddTriangles()
{
for (int i = 0; i < triangles.Length; i++)
{
newTriangles _= triangles*;*_
```

*}*

*for (int i = 0; i < triangles.Length / 3 - 1; i++)*

*{*

*newTriangles[triangles.Length - 1 + (i * 3) + 0] = triangles[];*

*newTriangles[triangles.Length - 1 + (i * 3) + 1] = triangles[];*

*newTriangles[triangles.Length - 1 + (i * 3) + 2] = triangles[];*

*}*

*mesh.triangles = newTriangles;*

*meshFilter.mesh = mesh;*

*meshCollider.sharedMesh = mesh;*

*}*

*}*

*This code is about as far as i’ve gotten. I can’t seem to figure out a way to add these triangles correctly.*