Hello everyone, I am just playing around with mesh creations and I am trying to make a terrain mesh, but I have hit two issues, that I will talk about now.

the first issue, is the terrain/triangles that I am creating seem to stop near the end of the amount specified and I am not sure why I kinda understand this code I have written it is based of unity but I know it isnt a copy and paste.

the second issue is that the other side of the triangles are still getting rendered obviously I am doing something wrong but I am not high skilled yet to understand why it does this.

Picture of the mesh in question:https://pasteall.org/pic/e05cc1381a054d61984adeaa12676d84

this code should be able to copy and paste it to your project as well just give a simple scene for the cube that acts as a guide for now.

``````extends Spatial

export var xsize = 20
export var zsize = 20

var new_verts = PoolVector3Array()
var new_tris:Array = []#[0,xsize + 1,1,xsize +1,1, xsize + 2]

var mesh_instance = MeshInstance.new()
var noise = OpenSimplexNoise.new()
var surface_tool = SurfaceTool.new()
var mesh = Mesh.new()

generate_triangle()

func _process(delta):
pass

func generate_triangle():
mesh_instance.translation = Vector3(0,0,0)
terrain()

surface_tool.commit(mesh)
mesh_instance.mesh = mesh

func terrain():
surface_tool.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
for x in xsize + 1: # Creates the positions for the triangles
for z in zsize + 1:
new_verts.append(Vector3(x,0,z)) # Actually adds the verts into the world space
for n in xsize + 1: # Creates the positions for the triangles
for s in zsize + 1:
for a in 6:
new_tris.append(0) # Create an empty array so that I dont get a invalid index

print(new_tris.size())
var tri_int = 0
var vert_int = 0
for z in zsize : # Creates the rows
for x in xsize: # Creates all the triangles needed
new_tris[tri_int + 0] = vert_int + 0
new_tris[tri_int + 1] = vert_int + xsize + 1
new_tris[tri_int + 2] = vert_int + 1
new_tris[tri_int + 3] = vert_int + xsize + 1
new_tris[tri_int + 4] = vert_int + 1
new_tris[tri_int + 5] = vert_int + xsize + 2

vert_int += 1
tri_int += 6 # this is so that it doesnt duplicate triangles
vert_int += 1

for i in new_tris.size(): # Adds triangles