Raycasting collision detection direction

hi

is there a way to do raycasting only on object in front of the camera?
when i do it now i detect object rear the camera

thanks

Hi!

Rear? But how? Anyway could you add some explanatory pics and more details of what you’re trying to achieve?

sorry i explain …

i move around the screen with arrows , lets say i move and face a wall, i can tell with raycasting there is a wall in front of the camera and i can stop the movement forward, but when i rotate the camera and the wall back end of the camera its still tell my there is collision, i want to detect on object in front of the camera view point

Is there any chance to see what happens in your code, when you do raycasting?
An editable live code example maybe?

i add image to illustrator want i want to achieve

Instead of performing the ray/intersection test with the entire scene, you can pass in a custom array of objects to Raycaster.intersectObjects(). This array represents the objects which are in front of your camera. You can compute these objects by transforming each object into view space and check if the position’s z coordinate is negative.

““You can compute these objects by transforming each object into view space””

how do i do this ?

Multiply the position vector in world space of a 3D object with the inverse world matrix of the camera (also known as view matrix).

https://threejs.org/docs/index.html#api/en/cameras/Camera.matrixWorldInverse