I am currently facing an issue with detecting the intersection between a box3 (acting as a wall) and the camera (serving as the moving player).
Below is the code snippet:
const wallgeometry = new THREE.PlaneGeometry( 200, 50 );
const wallmaterial = new THREE.MeshStandardMaterial( {color: 0x366078, side: THREE.DoubleSide} );
const wall1a = new THREE.Mesh( wallgeometry, wallmaterial );
wall1a.position.set(40,0,50); wall1a.rotation.y=0.5*Math.PI; scene.add( wall1a );
const humangeometry = new THREE.BoxGeometry( 3,3, 3 );
const humanmaterial = new THREE.MeshBasicMaterial( {color: 0x00ff00, transparent: false, opacity: 1.0} );
const human = new THREE.Mesh( humangeometry, humanmaterial );
**scene.add( human );
var humanhelper = new THREE.BoxHelper(human, 0x00ff00);
scene.add(humanhelper);
var humanbox3 = new THREE.Box3();
humanbox3.setFromObject(humanhelper);
camera.add(human);**
var wallhelper = new THREE.BoxHelper(wall1a, 0x00ff00);
scene.add(wallhelper);
var box3b = new THREE.Box3();
box3b.setFromObject(wallhelper);
Within the animate() function:
humanhelper.update();
humanbox3.setFromObject(humanhelper);
if(humanbox3.intersectsBox(box3b))
{
console.warn("Collision TRUE");
};
It seems that even though I'm moving the camera through the wall, no collision detection is being triggered. I have confirmed that the camera wireframe and position are updating correctly as it moves along with the player (human). //UPDATE Upon further investigation, it appears that the box3 representing the wall is not updating at all. I placed two walls in the same location, and the collision was detected. However, when I moved one of the walls away in the animation loop, the collision detection still indicated they were colliding. https://i.sstatic.net/oV89y.png