[SOLVED] Unbalanced Rigid Body shape do not falling over?

First of Hi, My query is about unbalanced Rigid Body shape, they do not fall over? I understand to edit a shape you have to recreate the Collision Shape, this is what I have pieced together

 geo.addControl(new RigidBodyControl(new HullCollisionShape(geo.getMesh())));  
 geo.getControl(RigidBodyControl.class).setMass(5f);
 geo.getControl(RigidBodyControl.class).setGravity(new Vector3f(0, -10f, 0));
 geo.getControl(RigidBodyControl.class).setDamping(0.9f, 0.99f);
 geo.getControl(RigidBodyControl.class).setFriction(0.9f);
 bulletAppState.getPhysicsSpace().add(geo);

1 Like

Each rigid body has a center of mass. If you create a body with an unrealistic center, its behavior will seem unrealistic.

A HullCollisionShape can be generated from arbitrary 3-D coordinates, but its center is always placed at (0,0,0). I can’t be sure, but I suspect the shape you created has (0,0,0) somewhere near its lower left corner. So that’s where Bullet (or MInie) puts the body’s center of mass.

Minie includes a simple example app that illustrates the importance of giving each dynamic rigid body a plausible center of mass. It’s discussed in Choosing collision shapes :: The Minie project .

So what your saying is by creating a mesh as apposed to having a compound shape, the centre of mass is lost, and in order to recreate the centre of mass I would need to create a compound collision shape or something like that, bit of a drat, the whole point was to not have to store a list of vectors separately from the spatial :sweat_smile: many thanks for your speedy reply sgold.

1 Like

You can still use a HullCollisionShape if you want, and the center of mass isn’t “lost”. But probably it’s not where you intended it to be.

If I were debugging this issue, the first thing I would do is add something to the scene to visualize the body’s center. In Minie that’s most easily done using:

bulletAppState.setDebugEnabled(true);
bulletAppState.setAxisLength(1f);

Yes just as you suspected sgold,

1 Like

Have you figured out how to make it fall over?

I am still having an issue, the change in centre of gravity is moving the Geometry, I taught at first it was a problem with my coordinate system, but it’s a bit deeper then that I think. I created a small temporary data structure until I know more, this is what I’m working with.

private CompoundCollisionShape createRigidBody(List<CubeData> data, Vector3f size) {
   CompoundCollisionShape CCS = new CompoundCollisionShape();
   float[] ms = new float[data.size()];
   int count = 0;
   for (CubeData cd : data) {
       CollisionShape box = new BoxCollisionShape(size);
       CCS.addChildShape(box, cd.getPos());
       ms[count++] = cd.getMass();
   }
   FloatBuffer massDistribution = BufferUtils.createFloatBuffer(ms);
   Vector3f inertiaVector = new Vector3f();
   Transform correction = CCS.principalAxes(massDistribution, null, inertiaVector);
   CCS.correctAxes(correction);
   return CCS;
}

1 Like

I don’t know where the other stuff comes from but if CubeData is minecraft style data then it’s probably 0,0,0 is the corner of the cube where as BoxCollisionShape will have 0,0,0 as the center of the cube and you have to adjust.

1 Like

I’m pretty sure it the way the Collision-Shape new Axes is attaching to the Geometry old Axes, you can see the way the new Axes is correct for the Collision-Shape, in theory if the Geometry had Axes guides in it’s centre there would be three sets of guides, and they would be the exact distance away that is causing this troubling offset. you could attach them both to a node and offset them that way I guess, but to know if that is the right solution is another thing, I have enough spaghetti code to deal with, with out generating more unnecessary.

RigidBodyControl assumes that the physics shape and the mesh have the same center and orientation. So if you adjust the body’s center, you need to also adjust the geometry’s center.

Hello again, the only method chains I can find that mention setting centre are these, but they don’t seem to have any effect?

geo.getMesh().getBound().setCenter();
geo.getModelBound().setCenter();
1 Like

Changing the mesh bounds won’t solve this issue. You need to change the mesh vertex positions relative to the Spatial controlled by the RigidBodyControl.

I can’t see the code that generates the meshes. If that code is difficult to modify, then adding a Node with the appropriate translation might be an easier solution.

Oh ok, that wont be a problem, the code I’m using just breaks up a block into separate polygons to make the mesh easier to edit, so that kind of functionality is already built in to it. I don’t know why that did not occur to me? thanks Sgold :slightly_smiling_face:

1 Like

I’m glad I was able to help.