Weird collision shape generation

Godot Version

4.4

Question

So I’m trying to generate a collision shape for a procedural mesh on runtime. It’s working except the collision shape seems to have extra faces


the light blue lines show the collision shape edges

generateMesh.gd
“”"
@tool
extends MeshInstance3D
@onready var collision: CollisionShape3D = $StaticBody3D/collision

var start = Vector2(0,0)
var dimensions = Vector2i(50,50)
var resolution = 0.5

var t = 0
func _process(delta: float):
t += 1

var terrain = Grounddata.Terrain(start,dimensions,resolution,t)
mesh = ArrayMesh.new()
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES,terrain)

var convex = ConvexPolygonShape3D.new()
convex.points = terrain[0]
collision.shape = convex

“”"
Grounddata.gd
“”"
@tool
extends Node

func Terrain(start, dimensions, resolution,t):
var terrain =
terrain.resize(ArrayMesh.ARRAY_MAX)

var verts = PackedVector3Array()
var indices = PackedInt32Array()

#var dst = Vector2(50,50)

for y in range(dimensions.y+1):
	for x in range(dimensions.x+1):
		verts.append(Vector3(x * resolution + start.x, sin(deg_to_rad(x*10+t))+sin(deg_to_rad(y*10+t)), y * resolution + start.y))


for y in range(dimensions.y):
	for x in range(dimensions.x):
		indices.append(x + y*(dimensions.x+1))
		indices.append(x + y*(dimensions.x+1)+1)
		indices.append(x + (y+1)*(dimensions.x+1)+1)
		
		indices.append(x + (y+1)*(dimensions.x+1))
		indices.append(x + y*(dimensions.x+1))
		indices.append(x + (y+1)*(dimensions.x+1)+1)


terrain[Mesh.ARRAY_VERTEX] = verts
terrain[Mesh.ARRAY_INDEX] = indices

return terrain

“”"
sorry about the code formating
still not sure how to do it

So I tried changing the convexpolygon to a concave
it doesn’t work but it’s promising
“”"@tool
extends MeshInstance3D
@onready var collision: CollisionShape3D = $StaticBody3D/collision

var start = Vector2(0,0)
var dimensions = Vector2i(50,50)
var resolution = 0.5

var t = 0
func _process(delta: float):
t += 2

var terrain = Grounddata.Terrain(start,dimensions,resolution,t)
mesh = ArrayMesh.new()
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES,terrain)

#collision handling
var index := PackedVector3Array()
for i in range(terrain[Mesh.ARRAY_INDEX].size()):
	if i < terrain[Mesh.ARRAY_INDEX].size() - 2:
		index.append(Vector3(terrain[Mesh.ARRAY_INDEX][i],terrain[Mesh.ARRAY_INDEX][i+1],terrain[Mesh.ARRAY_INDEX][i+2]))
	
var concave = ConcavePolygonShape3D.new()
concave.set_faces(index)
collision.shape = concave"""

if I replace the index with terrain[Mesh_ARRAY_VERTEX], then It kinda works


still broken though
the collision is in small lines

Hey @Sjpark01

Those seems to be shadow acne. This seems to be relate to shadow/light settings. Usually setting clipping distances or tweaking the light that provides the shadow fixes it