Raycast pick entity with offset camera

Maybe just try this. If you have mouse coordinates xm, ym, viewport offset vx, vy and viewport size dx, dy, you compute coordinates to pass to this screenToWorld like this:
x = (xm - vx) / dx
y = (ym - vy) / dy

and just to be clear, by mouse coordinates xm and ym I mean normalized coordinates, so if you have screen coordinates x and y, and device screen size device.clientRect.width and .height:
xm = x / device.clientRect.width
ym = y / device.clientRect.height

2 Likes