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