Is there a way to create a collision mesh of a posed animated character at runtime?

Godot Version

4.4.1

Question

I am working on an fps and I need to be able to precisely detect collisions for my animated enemies. The primitive shapes connected to bones wont do. I’m hoping to send a raycast to the center of the screen, and use a large capsule to see if it hits an enemy. If it hits I would then create a precise collision mesh of the enemy during its animation. If it hits that then I know it will have been hit for real. I know I can create a collision mesh of a character in its default pose in the editor, but I don’t know if there is a way to create a posed collider in code at runtime. Is there a way to do that?

I’d not recommend doing that but, if you really need it then, you’ll need to use MeshInstance3D.bake_mesh_from_current_skeleton_pose() to get a new Mesh and use Mesh.create_trimesh_shape() or Mesh.create_convex_shape() to get the Shape3D that you can use in a CollisionShape3D node.