Prevent object from moving outside of the wall

I’m currently stuck and I’ve already tried with BoxHelper to allow collision detection between the box and the wall but no success. So what I need to do to prevent user to drag the box outside the wall ?

Here is what I’ve so far

Regards.

THREE.BoxHelper is not intended for collision detection. It’s for visualizing the world-axis-aligned bounding box of a 3D object.

There are several approaches to achieve basic collision detection. The most obvious is to maintain for each wall an instance of THREE.Plane and for the box and instance of THREE.Box3. These entities will act as mathematical representations of your meshes which you can use for very fast intersection tests.

Every time the box is translated via dragging you can use Box3.intersectsPlane() to verify whether the box intersects with the planes. If so, you do not allow the translation.

2 Likes