Aligning mesh to a dynamic rapier 3D rigidbody

34 views Asked by At

Here I load the gltf file into the world and make rigid bodies for it, but when the rigidbody is dynamic then the visual mesh stays in air and the rigid body falls on the ground

What I am trying to do is make the mesh follow/move with the rigidbody

    let gltf = gltf_assets.get(&main_scene.handle_dyn);

    if let Some(gltf) = gltf {
        let scene = gltf.scenes.first().unwrap().clone();
        commands.spawn(SceneBundle { scene, ..default() });
        for node in &gltf.nodes {
            let node = gltf_node_assets.get(node).unwrap();
            if let Some(gltf_mesh) = node.mesh.clone() {
                let gltf_mesh = gltf_mesh_assets.get(&gltf_mesh).unwrap();
                for mesh_primitive in &gltf_mesh.primitives {
                    let mesh = mesh_assets.get(&mesh_primitive.mesh).unwrap();
                    commands.spawn((
                        Collider::from_bevy_mesh(mesh, &ComputedColliderShape::TriMesh).unwrap(),
                        RigidBody::Dynamic,
                        TransformBundle::from_transform(node.transform),
                    ));
                }
            }
        }
        main_scene.is_loaded = true;
    } 
0

There are 0 answers