Physics body doesn't move with mesh animation

Hi,

I’m working with a mesh that has both physics enabled and an animation. I noticed that when the animation starts, the mesh moves visually as expected, but the physics body stays in its original position and does not follow the animation.

It seems like the physics shape is not updating along with the animation.

How can I make the physics body follow the mesh animation correctly

Thanks :folded_hands:

cc @Cedric

When you say the physics body does that mean a collider for a body part or a capsule for the entire mesh?

If its just a collider mesh then attach it to the bone and you should be good, if its the entire capsule then just attach it to the hips id assume?

I imported a .glb file that includes some meshes, such as a door, with an opening animation.
I added a PhysicsAggregate to the door, but when the animation starts playing, the physics body doesn’t move with it.

const mesh= await ImportMeshAsync("models/environment/mesh.glb").then(res => {

  res?.meshes?.forEach(m => {

    if (m.getTotalVertices() > 0) {
      const landPhysics = new PhysicsAggregate(
        m,
        PhysicsShapeType.CONVEX_HULL,
        {
          mass: 0,
        },
      );
    }
  })
  return res
})

A body with a mass of 0 will be static and is expected to not move.
It’s possible to switch to Animated mode and control the body position/orientation. Check this doc page for the different motion types and preStep : Babylon.js docs

1 Like