Hi everyone,
I’m developing a game using BabylonJS and encountering an issue with physics synchronization for a specific mesh within an animated GLB model.
My usual workflow for handling collision on animated meshes involves these steps:
- Import the GLB model.
- Find the target mesh within the model’s hierarchy that requires collision detection.
- Create a
PhysicsBody
for this mesh (typicallyPhysicsBody.STATIC
). - Create a
PhysicsShapeMesh
using the target mesh’s geometry to get accurate collision bounds. - Set
physicsBody.disablePreStep = false
. My understanding is that this tells the physics engine to update the body’s transform based on the mesh’s transform before each physics step, which is necessary for animations that move the mesh.
This approach has been successful for several models. However, I’ve run into a problem with a particular GLB model. When I apply this exact procedure to certain meshes within this model, like head
or body
, the PhysicsBody
correctly follows the mesh’s animation as expected.
The issue arises when I try to do the same for a specific mesh named hand_primitive2
. Even though I follow the same steps and ensure physicsBody.disablePreStep = false
is set, the PhysicsBody
for hand_primitive2
does not follow the animated mesh. It remains static at its initial position/orientation, while the visual mesh animates correctly.
To demonstrate this clearly, I’ve prepared a Playground example. It loads the model, sets up the physics for hand_primitive2
as described, starts an animation, and enables the physics viewer. You can see the hand mesh moving, but its physics shape (visualized by the viewer) stays behind:
Playground Link: https://playground.babylonjs.com/#P9N31W
I’m puzzled as to why this specific mesh (hand_primitive2
) behaves differently from others (head
, body
) in the same model using the same setup.
- Could there be something specific about
hand_primitive2
? Perhaps its place in the hierarchy, its skinning/bone weights, or how the animation updates its final world matrix? - Is
PhysicsShapeMesh
combined withdisablePreStep = false
the correct approach for skinned/animated sub-meshes like this? - Is there another factor I might be overlooking?
I did search the forums but couldn’t find a similar case where the method works selectively within the same animated asset.
Any insights or suggestions on what might be causing this discrepancy and how to resolve it would be incredibly helpful!
Thanks in advance for your time and expertise.