At runtime, you can indeed use
create_trimesh_collision() on the
It creates a child static body with the mesh as collision shape. How do you know it doesn't work? It might be a bit impractical to customize though.
If you want to setup the node hierarchy yourself, you can instead generate only the
Shape using the method of the same name from the
Mesh resource directly: http://docs.godotengine.org/en/3.1/classes/class_mesh.html#class-mesh-method-create-trimesh-shape
This returns a
Shape which you can assign to a
CollisionShape node, which you can itself place under a physics body of your choice.
Note: if your body is not static, you may want a convex shape, otherwise it won't work.
Although, why do you need to create collisions at runtime? You can make them in the editor and turn the shapes on/off at runtime.
If you do it at runtime from an already-built
Mesh, be aware that Godot actually downloads it back from the graphics card, builds a BVH, gives it to Bullet, which builds a BVH again. This is fine in editor but in game it's 2 to 3 times slower than it should be.
This may be fine for a low amount of objects, but if you plan doing this on hundreds of meshes and experience performance issues, consider baking them in editor beforehands anyways.
If they are procedurally generated, there is a way to bypass the overhead but it's only efficiently done using C++: https://github.com/Zylann/godot_voxel/issues/54