Collision detection in three.js

Two example of collision of obj models of 3D, is this feasible?

I did not find such an example in the three.js framework.

1 Like

three.js does not provide a system for collision detection or colliders. You have basically two options: You can implement collision detection with some math and coarse bounding volumes like THREE.Sphere or THREE.Box3 or you try to integrate a physics engine in your app. Check out the following examples to get an impression of this approach:

https://threejs.org/examples/physics_ammo_rope

For most apps, a real physics engine is actually an overkill. Like mentioned above, you can implement a basic collision detection with more or less simple math like in the following example. Check out the code section in the render function which ensures the balls are kept inside the room and collide against each other.

https://threejs.org/examples/webxr_vr_ballshooter

6 Likes

The link to the second example 404s: https://threejs.org/examples/webvr_ballshooter.html

1 Like

Thanks for the heads up! Both links are updated.

Where can one see the code of the second example? I don’t see it in the source.

I need to implement collision detection and I am looking at this example using raycasting but I don’t understand but it seems one can only check if the player collided with an object. I need to check and return the object that collided with the player.

The code for keeping objects inside the virtual room is in the render() function.