diff --git a/packages/lib/src/utils/picker.tsx b/packages/lib/src/utils/picker.tsx index 14296793..7a0709fe 100644 --- a/packages/lib/src/utils/picker.tsx +++ b/packages/lib/src/utils/picker.tsx @@ -53,9 +53,9 @@ const getEntityAtPointerEvent = async (app : AppBase, picker: Picker, rect: DOMR const x = e.clientX - rect.left; const y = e.clientY - rect.top; - // Account for canvas scaling - const scaleX = canvas.width / rect.width; - const scaleY = canvas.height / rect.height; + // Scale calculation using PlayCanvas's DPR + const scaleX = canvas.width / (rect.width * app.graphicsDevice.maxPixelRatio); + const scaleY = canvas.height / (rect.height * app.graphicsDevice.maxPixelRatio); // prepare the picker and perform picking try { @@ -67,7 +67,6 @@ const getEntityAtPointerEvent = async (app : AppBase, picker: Picker, rect: DOMR if (!meshInstance) return null return meshInstance?.node as Entity; - return null } catch { // The picker can fail if the camera is not active or the canvas is not visible return null;