PhysicsCollisionListener not calling collision()

I’ve got a properly structured subclass (“BulletControl”) of a RigidBodyControl implementing a PhysicsCollisionListener interface, but when I see the collision occur properly with physics (2 rigidbodies, a moving bullet and a static block), the “collision” method isn’t invoked.



Here’s the code to setup the physics object and such:

[java]if (binding.equals(“Fire”)) {

if (value) {

SphereCollisionShape sphereShape =

new SphereCollisionShape(.2f);

bulletsphere = new Sphere(3, 4, 1);

//pbullet = new PhysicsCharacter(new SphereCollisionShape(.5f), 0f);

bulletnode = new Node();

geombullet = new Geometry(“Bullet”, bulletsphere);

Material mat = new Material(assetManager, “Common/MatDefs/Misc/SimpleTextured.j3md”);

mat.setTexture(“ColorMap”, assetManager.loadTexture(“Textures/circuit1.jpg”));

geombullet.setMaterial(mat);

//bulletnode.attachChild(geombullet);

bulletcontrol = new BulletControl(sphereShape, 1f);

getPhysicsSpace().add(bulletcontrol);

geombullet.addControl(bulletcontrol);

rootNode.attachChild(geombullet);

//bulletcontrol.setKinematic(true);

bulletcontrol.setGravity(Vector3f.ZERO);

bulletcontrol.setPhysicsLocation(cam.getLocation().add(cam.getDirection().mult(2f)));

bulletcontrol.setLinearVelocity(cam.getDirection().mult(25f));

}

}[/java]



Am I doing it right? I checked and there’s not a whiff of a call to that method according to the debugger.

How are you registering your PhysicsCollisionListener implementation?

[java]public class BulletControl extends RigidBodyControl

implements PhysicsCollisionListener {



public boolean collidedWithMap = false;



public BulletControl(CollisionShape shape, float mass) {

super(shape, mass);

}



public void prePhysicsTick(PhysicsSpace space, float f) {

// apply state changes …

}



public void physicsTick(PhysicsSpace space, float f) {

// poll game state …

}



public void collision(PhysicsCollisionEvent event) {

//if ( event.getNodeA().getName().equals("Map") ) {

// node = (Node)event.getNodeA();

/** … do something with the node … */

collidedWithMap = true;[/java]

you to need to add the collision listener to the physics space. try bulletAppState.getPhysicsSpace().addCollisionListener(this);

Thanks! That did it! :slight_smile: