2
votes

I'm working on something with three.js where i need a way to handle collisions between objects very generally. I was thinking of using cannon.js since it supports the primitives i need but i don't always particularly need/want any of the overhead of the physics (lets say for detecting a bullet hitting a particular enemy), i just mainly want to use it for collision detection in a lot of cases since im not interested in going down the rabbit hole of writing my own general collision detection engine.

Basically what i'm asking is if there's a relatively simple way to use cannon.js, or perhaps some other javascript physics library to test for object/object object/terrain collisions and determine if objects are/aren't colliding. If i could get stuff like penetration depth, the normal of the collision etc. that would be even better.

would i be better off using physijs if i really wanted things to be tightly and effeciently integrated with my three.js code? it seems to also have what i need, but the performance seemed pretty bad from the demos on its main page.

thanks!

1

1 Answers

1
votes

The developper, Chanderprall (think I got that right) made Physijs an easy-to-use plugin for physics with THREE. He built it on top of ammo.js and does have an experimental cannon.js branch (unfortunatly only supports primitive shapes for now) which I guess works like the normal one.

Personally, I think the entire library should only be used when you are dealing with real-time physics, where objects have dynamic positions, etc. If you simply wanted some collision detections without a physics engine, just use the THREE.Raycaster, which can detect if meshes (calculated using their bounding boxes) are intersecting using the intersectObjects method. You could quickly adapt it to detect how far an object went inside another object with some clever code.

http://webmaestro.fr/collisions-detection-three-js-raycasting/