Currently, I am experimenting with raycasting to determine if my mouse is pointing at an object. The function seems to be working fine when the object is not being touched - it correctly prints out "didnt touch". However, when the object is touched, it stops printing "didnt touch" and doesn't print "touch" either. As far as I understand, there are only two possible outcomes for the if statement - either === or not, right? So why isn't my code functioning properly? Any assistance would be greatly appreciated.
function animate(){
renderer.render(scene,camera);
sLightHelper.update();
rayCaster.setFromCamera(mousePosition,camera);
var intersects = rayCaster.intersectObjects(scene.children);
if ( house != undefined ){
for(let i = 0; i < intersects.length; i++){
if(intersects[0].object.id === house.ID){
console.log("touch");
}
else{
console.log("didnt touch");
}
}
console.log("finished");
}
else{
console.log('not ready')
}
}