I am trying to get rid of a node when it collides with anything but it stays and calls the collisionListener multiple times.
The node holds a sphere and a particle Emitter and it collides randomly with one of 6 Torus all right next to each other forming a target shape. When i run it most of the time the Sphere Node gets stuck in The torus and never goes away.
collisionListener:
[java]
private PhysicsCollisionListener collisionListener = new PhysicsCollisionListener() {
public void collision(PhysicsCollisionEvent event) {
ColorRGBA start=null, end=null;
Vector3f postion=null;
SpellBall ball=null;
/* Check if one of the objects collided was a spell Ball */
if(event.getNodeA().getClass()==SpellBall.class){
/* Get starting and ending colors */
ball = (SpellBall) event.getNodeA();
postion = ball.getLocalTranslation();
rootNode.detachChild(ball);
ball.removeFromParent();
ball.detachAllChildren();
start = ball.getElement().getStartColor();
end = ball.getElement().getEndColor();
prevBallA = ball;
}
if(event.getNodeB().getClass()==SpellBall.class){
/* Get starting and ending colors */
ball = (SpellBall) event.getNodeB();
postion = ball.getLocalTranslation();
rootNode.detachChild(ball);
ball.removeFromParent();
ball.detachAllChildren();
if(start!=null){
ColorRGBA temp = ball.getElement().getStartColor();
start = start.mult(temp);
}else{
start = ball.getElement().getStartColor();
}
if(end!=null){
ColorRGBA temp = ball.getElement().getStartColor();
end = end.mult(temp);
}else{
end = ball.getElement().getStartColor();
}
prevBallB = ball;
}
if(ball!=null){
System.out.println(ball);
}
if(start!=null && end!=null && postion!=null){
Explosion explosion = new Explosion(
"Explosion "+explosions.size(), assetManager);
explosion.setFlameColor(start, end);
explosion.setupExplosion(renderManager);
explosion.setLocalTranslation(postion);
rootNode.attachChild(explosion);
explosions.add(explosion);
}
System.out.println(event.getNodeA().getClass().getName()+":"+event.getNodeB().getClass().getName());
}
};
[/java]