0 votes
func _generate_mesh():
var mesh = ArrayMesh.new()
var data = []
data[ArrayMesh.ARRAY_VERTEX] = vertices
data[ArrayMesh.ARRAY_TEX_UV] = UVs
data[ArrayMesh.ARRAY_INDEX] = indices
data[ArrayMesh.ARRAY_NORMAL] = normals
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLE_STRIP, data)

return mesh


asked Mar 19 in Engine by huahuapro (52 points)

1 Answer

+1 vote

This line returns a shape for use in collisions, but you aren't using the return value. So it runs for nothing.

You should grab the result of create_trimesh_shape and assign it to a CollisionShape node in your scene.

answered Mar 19 by Zylann (26,157 points)

thanks for the fast answer.
i'm new to coding and godot :(, can you tell me how to assign it to a Collisionshape node?

and here's my func that use:

func _initialize():
if is_initialized:

if block_map == null:

mesh_node = get_node_or_null(block_map)
if mesh_node == null:

mesh_node.mesh = _generate_mesh()
is_initialized = true

i try to code: meshmode.createtrimesh_shape(), but it gives an error.


Do you know how to setup collision shapes in the first place? I suggest you take a look at how they work: https://docs.godotengine.org/en/stable/tutorials/physics/physics_introduction.html

The shape you obtain from the generated mesh is a resource.
Your node should have (or be) a StaticBody node, with a CollisionShape node as child. CollisionShape has a property named shape, and that's the one you need to assign the return value of create_trimesh_shape().

are you the man who create the voxel plugin?
omg, i think you are!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.