I want to get the intersection of the ray with the box. What’s wrong with my code?
const ggeo = new THREE.BoxBufferGeometry(100, 200, 60);
const gmesh = new THREE.Mesh(ggeo, new THREE.MeshBasicMaterial({ color: 0x00ffff}));
gmesh.position.set(-150, 0, -10);
gmesh.visible = true;
gmesh.updateMatrixWorld();
scene.add(gmesh);
// intersection
var from = new THREE.Vector3(-10, 0, -10);
var to = new THREE.Vector3(0, 0, -1);
var raycaster = new THREE.Raycaster();
raycaster.set(from, to);
var intersects = raycaster.intersectObjects(gmesh as any, true);
if (intersects.length > 0) {
// no interseection !
}
There’s no intersection because your ray is shooting in a direction that doesn’t touch the mesh. Your box is at -150x, and your ray shoots from -10x in a direction that will never reach the box.
Then I don’t know. With (-1, 0, 0) then your raycast should point in the right direction, so it may be something else. Maybe you could create a demo in JSFiddle.net or Codepen.io so we can debug it more easily.