CollisionListener - it won't work.

Started by Jamison, August 20, 2006, 05:36:02 AM

Previous topic - Next topic

Jamison

Hello all. I'm having trouble getting collision detection with the CollisionListener to work. Here's some code for two objects - the second one being the object that collides with the first object.
block = Loader.load3DS("Block.3ds", 1f)[0];
block.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
block.translate(0, 3, 0);
block.setTexture("block");
world.addObject(block);

block2 = Loader.load3DS("Block.3ds", 1f)[0];
block2.setCollisionMode(Object3D.COLLISION_CHECK_SELF);
block2.addCollisionListener(this);
block2.translate(0, -3, 0);
block2.setTexture("block");
world.addObject(block2);

this is a JPanel which implements CollisionListener, and here's the methods for it.
public void collision(CollisionEvent e) {
System.out.println("HIT!");
}

public boolean requiresPolygonIDs() {
return false;
}

But whenever the second object (obviously) collides with the first object, it does not print out "HIT!" as it should. What's wrong here? Please help me.

Thank you,
Jamison

EgonOlsen

The collision listener is called in case of collisions. A collision in jPCT can be caused by calling a checkCollisionXXXX()-method or by calcMinDistance() or by similar methods, i.e. you have to check for a collision explicitly. It isn't called automatically. Maybe you are not doing this. At least i can't spot anything like this in your code.

Jamison

Oh... I didn't realize I had to call checkCollisionXXXX(). Thanks, I'll try that.

Btw, you should write a tutorial or something for jPCT - I can't find any and it'd be nice to have. ;)