+3 votes

When im using create_trimesh_collision to any ArrayMesh i just gets this error

create_trimesh_collision: Condition "!static_body" is true.
scene/3d/mesh_instance.cpp:571 @ create_trimesh_collision()

but create_convex_collision works fine.

i aloso tried create_trimesh_shape it gives no error but just returns null

any idea?

test code:

func _ready():
#planemesh - works fine
    var m = MeshInstance.new()
    m.mesh = PlaneMesh.new()
    m.transform.origin = Vector3(4,1,0)
    add_child(m)
    m.create_trimesh_collision()

#arraymesh - error
    var vertices = PoolVector3Array()
    vertices.push_back(Vector3(1, 0, 0))
    vertices.push_back(Vector3(1, 0, 1))
    vertices.push_back(Vector3(0, 0, 1))
    vertices.push_back(Vector3(0, 0, 0))

    var arr_mesh = ArrayMesh.new()
    var arrays = []
    arrays.resize(ArrayMesh.ARRAY_MAX)
    arrays[ArrayMesh.ARRAY_VERTEX] = vertices
    arr_mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLE_FAN, arrays)
    var m2 = MeshInstance.new()
    m2.mesh = arr_mesh
    m2.transform.origin = Vector3(0,1,0)
    add_child(m2)
    m2.create_trimesh_collision()
Godot version v3.3.2.stable official
in Engine by (193 points)
edited by

2 Answers

+1 vote
Best answer

Finally i found the solution, the trimesh doesnt work with Mesh.PRIMITIVE_TRIANGLE_FAN, but with Mesh.PRIMITIVE_TRIANGLES and add_triangle_fan()

so here is a working example

func _ready():
    var mesh = Mesh.new()
    var vertices = [Vector3(1,0,0), Vector3(1,0,1), Vector3(0,0,1),Vector3(0,0,0)]
    var UVs = [Vector2(0,0), Vector2(0,1), Vector2(1,1), Vector2(1,0)]
    var st = SurfaceTool.new()
    st.begin(Mesh.PRIMITIVE_TRIANGLES)
    st.add_triangle_fan(vertices,UVs)
    st.commit(mesh)

    $MeshInstance.mesh = mesh
    $MeshInstance/StaticBody/CollisionShape.shape = mesh.create_trimesh_shape()
by (193 points)
0 votes

Not sure why but create_trimesh_collision() only works when using GLES3. A workaround is using a StaticBody with a ConcavePolygonShape3D to which you add the faces.

by (254 points)
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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.