Collision help, different results with same code

I’m using a GhostControl attached to a RigidBody to move through space (with no gravity). When the player presses space a linearVelocity is applied in the direction he is facing moving him forward. When he collides with a box he is supposed to stop. This happens about 1/4 of the time, the rest of the time it just bounces off like normal.


public void prePhysicsTick(PhysicsSpace space, float f) {







public void physicsTick(PhysicsSpace space, float f) {

if(playerGhost.getOverlappingCount() > 0 && canCollide() && !isColliding())


isColliding = true;

System.out.println(“Ghost collision detected: isColliding(”+ playerGhost.getOverlappingCount() +") = " + isColliding());

}else if(isColliding() && playerGhost.getOverlappingCount() == 0) {

isColliding = false;

collisionNormal = null;

System.out.println(“Ghost collision not detected: isColliding(”+ playerGhost.getOverlappingCount() +") = " + isColliding());




public void collision(PhysicsCollisionEvent event) {

if(!canCollide()) return;

Spatial box= null;



box= event.getNodeA();

}else if(event.getNodeB().getName().equals(“box”))


box= event.getNodeB();


if(box!= null)


collisionNormal = event.getNormalWorldOnB();


System.out.print("Unknwon collision between: " + event.getNodeA().toString() + " and " + event.getNodeB().toString() + “n”);




When it works i get the output:

Ghost collision detected: isColliding(1) = true

When it doesn’t work i get:

Ghost collision detected: isColliding(1) = true

Ghost collision not detected: isColliding(0) = false

Any idea why sometimes it seems to maintain the overlap for the ghost, and sometimes it does not?

Do you move RigidBodies with mass 0 around using setPhysicsLocation?

Yes, here is the definiteion for the rigid body used for the boxs i’m colliding with:







boxPhys.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_01 | PhysicsCollisionObject.COLLISION_GROUP_02);


Thats wrong, you have to set it to kinematic mode and give it a mass if you want to move it and get proper results.