Problem raycaster with OrbitControls

Good afternoon.
I added a mesh plan to the scene and transferred this plan to the raycaster.
Added a small gray cube that will move with the mouse pointer.

function set_world() {
        let geo = new THREE.PlaneBufferGeometry( 1000, 1000 );
        geo.rotateX(- Math.PI / 2);
        geo.boundingSphere = null;
        geo.boundingBox = null;

        let mesh = new THREE.Mesh(geo, new THREE.MeshBasicMaterial({ visible: false }));
        mesh.name = 'world';
        mesh.position.set(0, 0, 0)

        return mesh;
}
let world = set_world();

let box_g = new THREE.BoxBufferGeometry(0.2, 0.2, 0.2);
let box_m = new THREE.MeshBasicMaterial({ color: 0x666666 });

let gray_box= new THREE.Mesh(box_g, box_m);
scene.add(gray_box);

this.events.onMouseMove = function onMouseMove(event) {
     var rect = renderer.domElement.getBoundingClientRect();
     elements.mouse.x = (event.clientX - rect.left) / (rect.right - rect.left) * 2 - 1;
     elements.mouse.y = - ((event.clientY - rect.top) / (rect.bottom - rect.top)) * 2 + 1;

     raycaster.setFromCamera(elements.mouse, camera.camera);
     let intersects = raycaster.intersectObjects([world]);
     if (intersects.length > 0 && intersects[0].object.name == 'world') {
            gray_box.position.set(intersects[0].point.x, 0, intersects[0].point.z);
     }
}

I check: I move the mouse here and there and the gray cube moves with the mouse pointer.


With the help of the OrbitControls I move the camera down, up, right, left, and scale. I try to move the mouse - everything is normal, the gray cube moves with the mouse pointer.

With the help of the OrbitControls, I turn the camera to the sides and here the raycaster breaks: the mouse pointer moves away from the gray cube. If you turn the camera more, then the pointer moves away from the gray cube even more.


If you move the camera to the sides or scale in OrbitControls, then there are no problems. The problem appears if you turn the camera !!!

I tried to use PointerLockControls (rotate the camera in all directions, move). There is no such problem here with the raycaster.

^^^ up the up ^^^

It should be fixable by enabling / disabling the controls, but to understand what’s happening a codepen or a sample code would be very useful (pictures are not that good with describing motion. :sweat_smile: )