how to enable the collision of ArrayMesh?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By huahuapro
func _generate_mesh():
var mesh =
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


:bust_in_silhouette: Reply From: Zylann

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.

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: mesh_mode.create_trimesh_shape(), but it gives an error.


huahuapro | 2020-03-19 23:50

Do you know how to setup collision shapes in the first place? I suggest you take a look at how they work: Physics introduction — Godot Engine (stable) documentation in English

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().

Zylann | 2020-03-20 00:37

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

huahuapro | 2020-03-20 06:36