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.
[java]@Override
public void prePhysicsTick(PhysicsSpace space, float f) {
if(isColliding())
{
setLinearVelocity(Vector3f.ZERO);
}
}
@Override
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());
}
//…
@Override
public void collision(PhysicsCollisionEvent event) {
if(!canCollide()) return;
Spatial box= null;
if(event.getNodeA().getName().equals(“box”))
{
box= event.getNodeA();
}else if(event.getNodeB().getName().equals(“box”))
{
box= event.getNodeB();
}
if(box!= null)
{
collisionNormal = event.getNormalWorldOnB();
}else{
System.out.print("Unknwon collision between: " + event.getNodeA().toString() + " and " + event.getNodeB().toString() + “n”);
}
}
}[/java]
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:
[java]
boxPhys.setPhysicsLocation(temp);
boxPhys.setMass(0);
boxPhys.setFriction(1);
boxPhys.setKinematic(false);
boxPhys.setCollisionGroup(PhysicsCollisionObject.COLLISION_GROUP_03);
boxPhys.setCollideWithGroups(PhysicsCollisionObject.COLLISION_GROUP_01 | PhysicsCollisionObject.COLLISION_GROUP_02);
[/java]
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.