Avoiding collision with the walls

image

Hi,
I am using Dragcontrols to drag the boxes placed in a large open box.
the small boxes pass through the walls of the open box.
is there any way to avoid this
Thanks in advance

Related:

Just a thought: use .clamp() method of THREE.Vector3() to “lock” your boxes inside the container.

Something like this (just a concept for the case when your box meshes are axes aligned, not tested):

var smallBox = new THREE.Mesh( _params_ ); // small box inside the container

var containerMesh = new THREE.Mesh( _params_ ); // container
var containerBox = new THREE.Box3().setFromObject(containerMesh); // container's bounding box

var smallBoxHalfSize = new THREE.Vector3();
var boxBox = new THREE.Box3().setFromObject(smallBox); // small box's bounding box
boxBox.getSize(smallBoxHalfSize);
smallBoxHalfSize.multiplyScalar(0.5);

var min = new THREE.Vector3.copy(containerBox.min).add(smallBoxHalfSize);
var max = new THREE.Vector3.copy(containerBox.max).sub(smallBoxHalfSize);

...
// somewhere in your mouse events
smallBox.position.clamp(min, max);
1 Like