I just created a simple environment with 2 spheres and making raycast between each other. From A to B I get intersection but not from B to A, why this can happen ?
here a fiddle
objs.forEach(obj => {
const Object = new THREE.Mesh(new THREE.SphereGeometry(1, 32, 32), new THREE.MeshBasicMaterial({
color: 0xff0000
}));
Object.position.set(obj.pos.x, obj.pos.y, obj.pos.z);
scene.add(Object);
});
objs.forEach(originObj => { // origin
const oPos = new THREE.Vector3(originObj.pos.x, originObj.pos.y, originObj.pos.z);
objs.forEach(destinyObj => { // destiny
if (originObj.id != destinyObj.id) { // only check with the others
const dPos = new THREE.Vector3(destinyObj.pos.x, destinyObj.pos.y, destinyObj.pos.z);
let dir = new THREE.Vector3();
dir = dir.subVectors(dPos, oPos).normalize();
const raycaster = new THREE.Raycaster();
raycaster.set(oPos, dir);
const intersects = raycaster.intersectObject(scene, true);
}
});
});
Thanks in advance