# Push raycaster into the camera direction and point it down

Hi guys. In my attempt to make some sort of a collision detection based on PointerLockControls and its example, I added 4 raycaster, each for one direction (f, b, l, r). Now everytime you would move, it would create the raycaster and move it along the coordinates either by +1 or -1 based on the velocity. Unfortunatelly, this solution for collision detection does not work as intended. It just likes to let you move into the object by like one unit. From what I understand, the problem is that my solution does not account for the camera rotation, since even if the velocity in some direction might be fine to use, it wouldnt account for the camera rotation and let the user pass even 2 units into an object sometimes. Would anybody be kind enough to help me with this thing, I have no idea how I could do this.
Here is the code in question:

``````			var cameraDirection = controls.getDirection(new THREE.Vector3(0, 0, 0)).clone();
// When moving forward
var mrc2c = controls.getObject().position.clone();
mrc2c.z = mrc2c.z += 1;
}else{
mrc2c.z = mrc2c.z -= 1;
}
var mrc2 = new THREE.Raycaster(mrc2c, new THREE.Vector3(0, - 1, 0), 0, 12);
var intersects = mrc2.intersectObjects(scene.children, true);
if(intersects.length > 0) {
canMove = false;
velocity.z = 0;
}
``````

Instead of using raytracing, maybe if would be a better choice to divide the terrane ( XZ plane ) to squares based on possibility of colliding with obstacles.