mrdoob/three.js — Issue #988: Problem intersecting only one object
Author: interactiveluke
Created: 2011-12-30 16:29:51+00:00
State: open

I'm trying to intersect one object in a scene with a ray and run a function when when it happens. Although, with my current code it seems to run the function every time the scene is intersected. Any help would be great, my code is below (This is run on a mouseUp event):

mouse.x = ( event.clientX / window.innerWidth ) * 2 - 1;
mouse.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

var vector = new THREE.Vector3( mouse.x, mouse.y, 0.5 );
projector.unprojectVector( vector, camera );

var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize() );

var intersect = ray.intersectObject( testSphere );

if ( intersect ) {

alert(intersect);

}