diff --git a/.changeset/fix-pointer-ray-origin.md b/.changeset/fix-pointer-ray-origin.md new file mode 100644 index 0000000..4fda7cb --- /dev/null +++ b/.changeset/fix-pointer-ray-origin.md @@ -0,0 +1,5 @@ +--- +"react-three-map": patch +--- + +Fix hover/raycast inaccuracy by deriving the pointer-event ray origin from the cursor position. diff --git a/src/core/events.ts b/src/core/events.ts index 3eae86e..209c8b2 100644 --- a/src/core/events.ts +++ b/src/core/events.ts @@ -22,7 +22,7 @@ export const events: Events = (store) => { if (state.camera.userData.projByViewInv) projViewInv.fromArray(state.camera.userData.projByViewInv); state.raycaster.camera = state.camera; - state.raycaster.ray.origin.setScalar(0).applyMatrix4(projViewInv); + state.raycaster.ray.origin.set(state.pointer.x, state.pointer.y, -1).applyMatrix4(projViewInv); state.raycaster.ray.direction .set(state.pointer.x, state.pointer.y, 1) .applyMatrix4(projViewInv)