How to generate a grid mesh

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By leo-pnt

Hi!
I’m trying to make a dynamic ocean mesh but I can’t figure out how to render the mesh correctly

In short, I’d just like to render a 10x10 mesh grid that looks like a plane
How can I do that ?

Here’s how it looks like in my head aha

Here is what I got so far (I can see weird triangles):

extends Spatial

onready var ig:ImmediateGeometry = $ImmediateGeometry
var t:float = 0.0

func _ready():
	pass

func _process(delta):
	ig.clear()
	ig.begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
	for i in range(-2, 2):
		for j in range(-2, 2):
			var height = sin(t + i + j)
			ig.add_vertex(Vector3(j, height, i))
	ig.end()

	t += delta
	if t >= 2 * PI:
		t = 0.0