How can I keep my raycasters in the same y rotation as my camera?

At the moment - my camera has four raycaster pointing outward at the base of the camera for collision detection. This is top down view:


When I move my camera, the raycasters follow my camera, but ignore it’s rotational changes. Like: (notice coloured lines)

Is it possible to get the raycasters to follow rotation.y like this:

When using Raycaster.setFromCamera(), the transformation of the camera should automatically honored.

Previously I had created the raycasters like so:

raycaster = new THREE.Raycaster( new THREE.Vector3(), new THREE.Vector3( 0, - 1, 0 ), 0, 20 );

forwardRaycaster = new THREE.Raycaster( new THREE.Vector3(), new THREE.Vector3( 0, 0, -1 ), 0, 5 );

backwardRaycaster = new THREE.Raycaster( new THREE.Vector3(), new THREE.Vector3( 0, 0, 1 ), 0, 5 );

horizontalRaycaster = new THREE.Raycaster( new THREE.Vector3(), new THREE.Vector3( -1, 0, 0 ), 0, 5 );

rightHorizontalRaycaster = new THREE.Raycaster( new THREE.Vector3(), new THREE.Vector3( 1, 0, 0 ), 0, 5 );

One pointing in each direction and then doing this in my animate:

raycaster.ray.origin.copy( camera.position );
raycaster.ray.origin.y -= 10;

as my use case is camera collision (first person) i am getting a bit confused by the mouse input. I understand this is a x,y coord so I tried using x:0. y:0 to just use the center of the cameras view. Is “mouse” just named this way because it’s intended use case is raycasting to simulate mouse clicking/picking?

I changed my animate to do this instead:

forwardRaycaster.setFromCamera({x:0,y:0},camera);
forwardRaycaster.ray.origin.y -= 10;

But all four rays are facing the same direction. The direction input from when I created the raycasters is overwritten i guess?

This may be incorrect in some ways - and i’m starting to get worried that inefficient animate function full of if statements and the like are going to ruin my project if i’m not careful. But i got my case working by taking some code from the setFromCamera function and do something like this.

forwardRaycaster.ray.origin.copy( camera.position );
forwardRaycaster.ray.origin.y -= 10;
forwardRaycaster.ray.origin.z -=10
forwardRaycaster.ray.direction.set( 0,0,-1 ).unproject( camera ).sub( camera.position ).normalize();