I'm currently working on creating a picking ray to determine if my 3D body in three.js has been clicked. I've tried following some advice from different sources like this post and this thread.
This is the code I have so far:
function checkClick() {
// Check for body hit on every click
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");
}
}
After learning about using `projector.pickingRay`, which simplifies the process compared to other examples, I tried implementing it into my code. However, I am encountering an issue where I always receive the "found nothing" message even though there is one object (model) in the scene. I have added this object to the `objects` array as required by `raycaster.intersectObjects`. I also attempted using `scene.children` instead, but still no luck. Can anyone provide insight into what might be going wrong here?
Any help would be greatly appreciated. Thank you!