Dynamic rigid bodies pass through each other

I’m currently working on Dynamic physics bodies in my game. I have a problem where the bodies pass right through each. I’m going to assume I’m missing a lot after I reworked the player control and seen the extra classes it relies on. Here is my code.

         RigidBodyControl tempBody;
         CollisionShape sceneShape = CollisionShapeFactory.createMeshShape(spatial);
         tempBody = new RigidBodyControl(sceneShape,spatial.getControl(PhysicsControl.class).getWeight());

When I add mass to my objects they fall right through surfaces. Where do I need to look to fix this ?

The code you posted seems fine to me… did you try to check the scene with bulletAppState’s debug enabled?

Try setCcdMotionThreshold and/or increasing physics precision (This is only to debug the issue)

I set the accuracy pretty high 1/200f

I set the ccd at 0.0001f

Those are really tight settings and still the same result. I’m using a simple box for the testing. It’s not a complicated mesh.

The default is 1/60
Wasn’t there a similar error with someone who has set it to to 1/80 a few days ago

Edit: Well…that was you -.-

I have my first clue. I slowed down the gravity enough where my player could reach the object before it fell through the surface. When my player capsule collided with the object it sets the object in motion.

The ground is a static weightless object.

The player control doesn’t fall through the ground.

The cube falls through the ground but reacts to the player control.

This is all I know so far.

As the code shows you are using MeshCollisionShape
Thought this may help
This is what wiki says about MeshCollisionShape:

A mesh-accurate shape for static or kinematic Spatials. Can have complex shapes with openings and appendages. +Limitations:
Collisions between two mesh-accurate shapes cannot be detected, only
non-mesh shapes can collide with this shape. This Shape does not work
with dynamic Spatials.

You may take a look wiki: https://jmonkeyengine.github.io/wiki/jme3/advanced/physics.html

Thanks , that solved all of my problems. For future reference for anyone reading this thread. Objects with a mass should be created as a dynamic shape. Objects with no mass should be a standard collision mesh shape.

         CollisionShape sceneShape;
         if (spatial.getControl(PhysicsControl.class).getWeight() > 0){
             sceneShape = CollisionShapeFactory.createDynamicMeshShape(spatial);
         } else {
             sceneShape = CollisionShapeFactory.createMeshShape(spatial);
1 Like