CollisionShapes reported as overlapping but they are not

Hello everyone and sorry for the bad title…

Here is my problem. I use bullet to detect collision between non trivial shapes (Hull collision shapes), using ghostControls. While debugging, the shapes appears properly, but doesn’t seem to collide as expected.

Here you can see to spatials with their ghostControls. The selected objet appears in blue, and does not collide with the other one.

To determine if a collision happens, I check if ghost.getOverlappingCount() > 0 with a PhysicsTickListener.

Here I just rotated a bit the selected objet. As you can see the collisionShapes doesn’t overlap, but the selected one is reported as overlapping with the other one (I appears in red).

I’m not sure but it looks like the default bounding box of the spatial is used instead of the hull collision shape, am I right?

Thanks for help :slight_smile:

Use physicsSpace.sweepTest() to check for overlaps.

Thanks for the prompt answer :slight_smile:

However, I don’t quite understand how to use properly the sweepTest, I followed this code (found on this forum):

[java]private int testIfFreePosition(RigidBodyControl physic) {

int numCollidingObj=0;

Transform actualPosition = new Transform(physic.getPhysicsLocation(), physic.getPhysicsRotation() );

Transform nextFakePosition = actualPosition.clone();

//basic test

nextFakePosition.setTranslation(actualPosition.getTranslation().x+1, actualPosition.getTranslation().y+1, actualPosition.getTranslation().z+1);

List<PhysicsSweepTestResult> ris = getPhysicsSpace().sweepTest(physic.getCollisionShape(), actualPosition, nextFakePosition);


//meybe we was INSIDE an object and we was moving away, so test in the other direction. This will also work if actualPosition is in the center of the other colliding object

ris = getPhysicsSpace().sweepTest(physic.getCollisionShape(), nextFakePosition, actualPosition );


return numCollidingObj;


The only thing I changed is that I make the second test only if the first one gives 0.

But now, I encounter major fps drops when ghosts are close to each other, and even more when they intersect.

Moreover, they are reported as colliding (ris.size() > 0) only if they barely touch each other, not when collision is deeper (look at the screenshots).

Note that fps is still low when they fully intersect but PhysicsSweepTestResult list is empty.

Am I missing something?

You don’t need ghost shapes, just use kinematic rigidbodies.

I replaced the ghost shapes by kinematic rigidbodies (I didn’t had much to change in the code), but I get the exact same result low fps and undected collisions.

By the way, why shouldn’t I use getOverlappingCount()?

Thanks for the help :slight_smile:

Cause ghost objects and other ghost objects don’t overlap.

okay I kept the rigidbodycontrols but instead of using a sweeptest(), I just use a collisionListener and check if the collision involves the selected object; if so, I set it red.

But what I didn’t manage to do is to set the original color when there is no collision.

What I try to do is to set the objet to its normal color (setBasicColor()) before the collision check, and if the collision() method from the collisionListener is called, the color is set to red (setRed()).

But the probem is that wherever I call setBasicColor(), it is done AFTER collision() is triggered, so my object remains basic even if setRed() is used.

I tried to put setBasicColor() in simpleUpdate(), in prePhysicsTick() and physicsTick() (from my physicsTickListener().

Where shall I put setBasicColor() so that it’s called BEFORE collision()?

You don’t need physics collision listeners when you do sweep tests :?

@normen said:
You don't need physics collision listeners when you do sweep tests :?

Sorry, I didn't explained really well...
As the sweepTest technique performed quite slowly and didn't reported "deep collisions" (see the screenshots), I looked for another way to detect collision between 2 rigid bodies. I thus tried with a collision listener, and it work just fine, collisions are detected properly and fps remains at 60.

But the well-named collision listener is only triggered when there is a collision. So I need to know when my rigid bodies are no longer colliding to set them to their original color. My first attempt was to set them to their original color on every physics tick, and if a collision happens, set it to red. But both prephysicstick and physicstick are called after collision(), so the color always come back to the original.
That's why I need a way to make sure I set the original color before collision() happens.

Thanks again, I really appreciate you help

Just set it back when you got no collisions for a frame instead of each frame?