Converts screen coordinates (for example, the mouse position) into world coordinates, taking into account the current camera offset.
ScreenToWorld(x, y)
{
x: worldX,
y: worldY
}
// Get the mouse position in world space
const { x, y } = ScreenToWorld(mouse.x, mouse.y);
// Use that position in a Raycast
Raycast(player.x, player.y, x, y, 800, true, player);
ctx.translate(offsetX, offsetY), which is why ScreenToWorld subtracts the offset.