Finite distance on raycaster

Hello people,

I know it’s a bit of a silly question as rays casted are set up to be infinite until they hit and object but I’m wondering, is there a way to set a finite distance of rays being casted? For example to set up the Ray so if it does not hit an object after say 1 unit in its respective direction then it would return null?

Thanks for any help in advance!!

Hi!
Have a look at the parameters of Raycaster constructor - near and far

1 Like

Yes I think you could set the far property to the units you’d like the ray length to be and that should do the job.

raycaster.far =  far.subVectors(destination, source).length();
1 Like