www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: Jamison on August 20, 2006, 05:36:02 am

Title: CollisionListener - it won't work.
Post by: Jamison on August 20, 2006, 05:36:02 am
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.
Code: [Select]
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.
Code: [Select]
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
Title: CollisionListener - it won't work.
Post by: EgonOlsen on August 20, 2006, 11:07:54 am
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.
Title: CollisionListener - it won't work.
Post by: Jamison on August 21, 2006, 01:11:56 am
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. ;)