Raycaster working fine only with arrow helper

Hi,

I have a scene involving a raycaster for a FPS. The camera uses PointerLock. I noticed that the raycasting only works fine at any distance if and only if I have an associated arrowHelper:

Declared variables:

  let directionVector = new Vector3();
  let positionVector = new Vector3();
  let caster;
  let object_set = new Set()

My animate function:

      let dir = camera.getWorldDirection(directionVector);
      let pos = camera.getWorldPosition(positionVector);
      let raycaster = new Raycaster(pos, dir.normalize());
   
      // if I disable the block below, it is not working
{
      scene.remove(caster);
      caster = new ArrowHelper(dir, pos);
      scene.add(caster);
}
      const intersections = raycaster.intersectObjects(scene.children, true);
      if (intersections.length > 0) {

        for (let x of intersections) {

          if (object_set.has(x.object.id)) {

            console.log("crossed", x.object.id)

          }

        }
   }

To me the arrowHelper is completely unrelated but apparently necessary.
I will keep it and make it transparent, but, any explanation please?

Thanks :+1:

I’m afraid you have to demonstrate the issue with a simple live example: Edit fiddle - JSFiddle - Code Playground

At least to me, I don’t see something strange in your code.

I will prepare an example thanks Mugen!