Imported gltf / glb and physics

Hello Everyone,

I am trying to attach physics to objects from an imported GLB file with objects already in the correct starting positions.

If the object with physics starts with x = 0 and z =0, and y an arbitrary height (so it is raised up in the air) the object falls to the ground as expected.

However if the object is off center (x and z are not 0) it will behave strangely. The center of mass is still at the origin?

In the playground examples below, I would like the cube to fall correctly even if it is not placed at center of the GLB file. My goal is to be able to position several objects using Blender, export a GLB file and then give them all physics.

The sphere is put there to indicate the center world origin.

Cube Offset (weird physics):

Cube centered (correct physics):

I’ve dug around the documentation and forum posts but it seems like most people are positioning the physics objects with Babylonjs and not the 3d program/GLB file. Is there a way to use the positioning from the GLB file?

cc @Cedric

This happens because the physics body, with its inertia matrix but without collision shape in at one position and a collision shape is at another, way to far from its body.

Collision are detected at 1 place in the world and the body reacts at another position.

Imagine a car having its center of gravity 100meters under the car but the wheels touch the ground. This would not be very realistic.

Make sure to have physicsRoot closer to the collision shapes.


Thank you! I got it now.

Would the best solution be to to do this?
physicsRoot.position.x = colliderMesh.position.x;
physicsRoot.position.y = colliderMesh.position.y;
physicsRoot.position.z = colliderMesh.position.z;

Yes, and if you have multiple collider shapes, set the body to be at the center.

1 Like