Compound Physics Setup

Hey guys… I am trying to get my head around compound physics setup for the new toolkit.

When playing with the example as

They main part of the code:

// Scale loaded mesh
        var skull = newMeshes[0]
        // Add colliders
        var bodyVisible = false;
        var sphere = BABYLON.MeshBuilder.CreateSphere("sphere1", {diameter: 0.5}, scene);
        sphere.position.y = 0.08;
        sphere.isVisible = bodyVisible;
        var box = BABYLON.MeshBuilder.CreateBox("box1", {size:0.3}, scene);
        box.position.y = -0.13;
        box.position.z = -0.13;
        box.isVisible = bodyVisible;

        // Create a compoundBody and add all children

        // Enable physics on colliders first then physics root of the mesh
        box.physicsImpostor = new BABYLON.PhysicsImpostor(box, BABYLON.PhysicsImpostor.BoxImpostor, { mass: 1 }, scene);
        sphere.physicsImpostor = new BABYLON.PhysicsImpostor(sphere, BABYLON.PhysicsImpostor.SphereImpostor, { mass: 2 }, scene);

        // Orient the compoundBody
        sphere.rotation.x = Math.PI/5;
        sphere.rotation.z = Math.PI/6;

The line of:

sphere.position.y = 0.08;

Now this is set BEFORE any child colliders are added so is the purpose of this position.y change on what is the root physics object to set the CENTER OF MASS for the compound ???

But the No Imposter sample

the same line seems to be offsetting the sphere a little bit up to COVER the head of the skull and DOES NOT seem to deal with CENTER OF MASS POSITION for the compondBody object.

This is really confusing me… I cant tell when and where i am support to set the root physics node position to SET THE CENTER OF MASS. But these two example dont seem to detailing ANY INFO on the center of mass… How the HECK does one calculate where that should be… Relative to WHAT… ZERO ???

The whole reason i am even messing around with No impostors and compounds is because that is Unity Collision are set up… But they setup and use the collision mesh as a CHILD of the gameobject. In babylon, you really got setup a SIMPLE mesh as the collider and add your detail mesh as a child of that… That is fine for HAND CODING everything out, but sucks for exporting from Unity.

I was hoping to make the new toolkit use the babylon compound system so any game object you export with a Rigidbody component that will act as the Physics Root With a No Impostor in Babylon.

Then any Collider Components will get added as child nodes in babylon using the various primitive collision meshes with Box, Sphere, Cylinder And Mesh Imposters. This also allow me to use the Unity Center X Y Z edit controls on the colliders to OFFSET the collider relative to is parent root physics object… This SEEMS like it would be perfect for the Unity To Babylon Export… And its exports and sets up fine… But the center of mass seems to be off… every example seems to have some arbitrary value for the physics root position.y with no explanation as to the rhyme or reason they came up with that value… Is that value calculable… I cant make export options WITHOUT understanding the process.

Anyways… can some please BREAK THIS DOWN to me so i can put in the exporter … Pretty Please :slight_smile:

Yo @Deltakosh, @trevordev or @sebavan … I know you busy guys too… But do think you can explain this physics root center of mass… Or do know of any other way to have the collision mesh as a child of the physics root.

That way the same entity you setup in Unity will be the same entity you move around in babylon… The collider is a child and just provider the COLLISION… But the root physics node with No Imposter is what you actually move around with physics API

PLEASE :slight_smile:

1 Like

Please be patient. @trevordev will soon be able to answer :slight_smile: (this is a day off today)

Hey (I realized it was an off day a bit late :joy:),

In these playgrounds there are 3 impostors, sphere, box and compoundBody. The position of the compound body is the center of mass. If I move it up you can see the center is at the top of the head.

See this playground:

So to setup the collision I would:

  • set the position of the visual mesh
  • position the collider meshes (eg. box and sphere) around the visual mesh
  • position where you want the center of mass (compound body)
  • add collider meshes as a child of the compound body
  • create physics imposters

Let me know if Im not making sense, hope this helps.

Hey @trevordev Thanks for getting back to me on day off.

I setup a playground with how the exporter will setup the physics root using skull.
Can you please look at and tell me if it looks good to you. And has no performance impacts you can see with the NO IMPOSTER physics root being the actual skull and the collision volumes for coverage are simple primitive child meshes (box and sphere)

Thanks bro :slight_smile:

Looks good to me

Yo @trevordev … I got a question about friction and restitution for compound physics setup.

When setting up MASS we set 0 mass on each child compound imposter (Box, Sphere,Etc)
and the final NO IMPOSTER we actually set the TOTAL MASS.

But what about friction and restitution… Where should those go… On EACH child compound collider or the final NO IMPOSTER physics root object ???

Just done a PR to add this method to docs

Can give url to these docs… pleae

I was just refering to your post with this PG . The link will be the compound page after the next docs build Create Compound Bodies - Babylon.js Documentation

I thought you had docs explaining the friction and restitution for coupons setup. More specific which one get friction… the compound child or the root no imposter ???

Yo @JohnK. Or @Deltakosh… Did I see somewhere about Softbody physics now available in BabylonJs.

Can you please send me the link how to use softbodies … please :blush:

Link available after next docs build. Here is a PG to wet your appetite

Docs will also explain limitations.

Doc: Create Soft Bodies - Babylon.js Documentation


You should set friction on the root “no impostor”

See child impostor friction has no impact