Hey guys… I am trying to get my head around compound physics setup for the new toolkit.
When playing with the example as https://www.babylonjs-playground.com/#492ZK0#8
They main part of the code:
// Scale loaded mesh
var skull = newMeshes[0]
skull.scaling.scaleInPlace(0.01);
skull.position.set(0,0,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
sphere.addChild(skull);
sphere.addChild(box);
sphere.position.y+=3;
// 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 https://www.babylonjs-playground.com/#492ZK0#7
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