+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)

#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[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)
Godot version v3.3.2.stable official
in Engine by (195 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()

    $MeshInstance.mesh = mesh
    $MeshInstance/StaticBody/CollisionShape.shape = mesh.create_trimesh_shape()
by (195 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 Frequently asked questions and 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 [email protected] with your username.