dimforge / rapier

2D and 3D physics engines focused on performance.
https://rapier.rs
Apache License 2.0
3.93k stars 244 forks source link

Collision detection without rigid bodies #407

Closed FilipPiktiv closed 1 year ago

FilipPiktiv commented 1 year ago

How would I go about utilizing only the collision detection part? I don't need any collision solving I basically just want colliders that I can move around, and react to intersections.

Can I make this example work without rigidBodies?

` const world = new RAPIER.World({x: 0, y: 0});

const colliderDescA = RAPIER.ColliderDesc.ball(1000)
  .setSensor(true)
  .setTranslation(100, 100);

const a: RAPIER.Collider = world.createCollider(colliderDescA);

const colliderDescB = RAPIER.ColliderDesc.ball(1000)
  .setSensor(true)
  .setTranslation(300, 100);

const b: RAPIER.Collider = world.createCollider(colliderDescB);

world.step();

let intersections = world.intersectionPair(a, b);
// Logs false
console.log(intersections);

`

sebcrozet commented 1 year ago

Hi! By default, collision-detection is disable between two colliders unless at least one of them is attached to a dynamic rigid-body. You can enable it explicitly by setting the colliders’ active collision types to ActiveCollisionTypes::all() (though technically, you only need ActiveCollisionTypes::FIXED_FIXED).