Hey there, I'm facing an issue with Raycasting and haven't been able to solve it yet. I need some help with keeping the Raycaster in the center at all times. Even when I move my camera and look in different directions, I want the Raycaster to remain in the center and update accordingly. Here's the code snippet I'm using with raycasting:
var raycaster = new THREE.Raycaster();
var arrow = new THREE.ArrowHelper( raycaster.ray.direction, raycaster.ray.origin, 100, Math.random() * 0xffffff );
scene.add( arrow );
var intersects;
function sec(){
requestAnimationFrame(sec);
var directionVector = new THREE.Vector3();
var positionVector = new THREE.Vector3();
var b = camera.getWorldDirection(directionVector);
var c = camera.getWorldPosition(positionVector);
raycaster.setFromCamera( b,camera );
arrow.position.copy(camera.position);
arrow.setDirection(raycaster.ray.direction);
intersects = raycaster.intersectObjects( scene.children );
if(intersects.length>0){
intersects[0].object.material.color.set( 0xff0000 );
}
else if(intersects.length<1 && casted){
for(var i=0; i<arr.length; i++){
arr[i].material.color.set( 0x8f8f8f );
}
}
camera.updateProjectionMatrix();
camera.updateMatrixWorld();
}
Would appreciate any guidance on this, thanks!