i am trying to build a picking ray to see if my 3D body in three.js has been clicked. It doesn't work at the moment and i followed these Three.js raycast produces empty intersects array and these three.js Raycaster intersectObjects tips.
My current code is this:
function checkClick() {
// On every click, check for body hit
clickInfo.x = event.clientX;
clickInfo.y = event.clientY;
var x = ( clickInfo.x / window.innerWidth ) * 2 - 1;
var y = -( clickInfo.y / window.innerHeight ) * 2 + 1;
var objects = [];
objects.push(model);
var raycaster = projector.pickingRay(directionVector.clone(),camera);
var intersects = raycaster.intersectObjects(scene.children);
if (intersects.length) {
alert("found something");
}
else {
alert("found nothing");
}
}
I've learned now that projector.pickingRay saves me a lot of work since in the 2nd linked example above the user needed to calculate all that alone before. But it doesn't work. I don't get any JS error, just the "found nothing" messages (the intersects array is empty). I do have one single object in the scene (model) which i add to objects because i know raycaster.intersectObjects needs an array as its parameter. It still doesn't work. Then i followed the tip in the first linked example and used scene.children instead. Still it always gives "found nothing". Why? What am i doing wrong?
Thanks a lot for any help.