mrdoob/three.js — Issue #1015: How to detect collisions when changing mouse direction with THREE.FirstPersonControls?
Author: danieljack
Created: 2012-01-03 19:50:30+00:00
State: open

I have checked http://oos.moxiecode.com/js_webgl/ray_collision/index.html example to detect collisions but now i am wondering how to detect collisions using the first person controls included in three.js when i change mouse direction. Checking some examples , i wonder it is something like the next code but it doesnt work. I am also wondering what does the other projectors projectObjects ( vector, camera ) and projectScene ( scene, camera, sort ).

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

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

var ray = new THREE.Ray( camera.position, vector.subSelf( camera.position ).normalize());
var hits = ray.intersectScene(scene);
if(hits.length>0 && hits[0].distance<50)
{
// hit
}