How to check for collisions in ThreeJS?

1.5k views Asked by At

I just wanted to know what's the best way to check with 100% accuracy for collisions in ThreeJS ? I'm new, but I'm not afraid of long formulas or bad documented code.

As I found nothing, I was wondering about implementing sphere-sphere collisions (easy), then sphere-face collisions (I can do sphere-plane collisions easily, don't know about sphere-face), and finally then face-face collisions (I can do plane-plane collisions easily, don't know about face-face). A little optimisation would be to check only collisions with faces which normals are opposed.

But coding all of this takes time, so I was wondering if someone already made such a thing. (And I think so, else, it would be very disturbing)

Thanks for your answers !

2

There are 2 answers

1
Falk Thiele On

There is a threex-extension called colliders from jetienne, which looks lightweight and could solve your needs.

When you want to throw some more performance at it you can use a physics engine like physijs or Cannon.js

0
pailhead On

There is also an example of using octrees with three.js. You should probably use most of these tests that you've mentioned. Test at a bounding box / sphere level to figure out which objects are close to being intersected that they need a more detailed check. Octrees / quad trees to partition terrain, possibly even meshes, in order to speed things up.