rapier.js icon indicating copy to clipboard operation
rapier.js copied to clipboard

why `wolrd.contactsWith` callback never gets called?

Open TheMetaverseEngineer opened this issue 1 year ago • 4 comments

const bodyDesc = RigidBodyDesc.dynamic()
      .setTranslation(startPos.x, startPos.y)
      .setLinearDamping(0)
      .setLinvel(-this.speed, 0)
    this.rb = Physics.instance.world.createRigidBody(bodyDesc);

    const colliderDesc = ColliderDesc.ball(this.size);
    const collider = Physics.instance.world.createCollider(
      colliderDesc,
      this.rb
    );
    Physics.instance.world.contactsWith(collider, (collider2) => {
      console.log(
        "🚀 ~ file: Bullet.physics.ts:58 ~ BulletPhysics ~ Physics.instance.world.contactsWith ~ collider2:",
        collider2
      );
    });

i don't know why but my callback never gets called. I couldn't find any examples!

TheMetaverseEngineer avatar Jul 15 '23 17:07 TheMetaverseEngineer

Have you found the reason, is not working too

wezzzyang avatar Oct 19 '23 06:10 wezzzyang

Popping in just to say that this happens for me too. Also happens for intersectsWith. Neither seem to actually get called.

I'm pretty confident that the masks are set up properly because I can see the event coming through drainCollisionEvents.

Tresky avatar Apr 14 '24 13:04 Tresky

These methods are not registering an event handler that will get called when a contact/intersection is detected. The callback are called only if there is any contact at the moment you call contactsWith. So, whenever you need to check these contacts (typically once per frame, after the physics step), you need to call .contactsWith again.

sebcrozet avatar Apr 14 '24 13:04 sebcrozet

OH! Well that's my problem. I must've misunderstood that in the docs. Thanks Seb!

Tresky avatar Apr 14 '24 13:04 Tresky