Author Topic: CollisionListener - it won't work.  (Read 3964 times)

Offline Jamison

  • byte
  • *
  • Posts: 12
    • View Profile
CollisionListener - it won't work.
« 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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
CollisionListener - it won't work.
« Reply #1 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.

Offline Jamison

  • byte
  • *
  • Posts: 12
    • View Profile
CollisionListener - it won't work.
« Reply #2 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. ;)