From 04139be6717f6f1e4537347e15d1523db0149fe5 Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Wed, 4 Sep 2024 08:23:42 +0200 Subject: [PATCH] fix: Account for viewport position in sprite backend --- backends/bevy_picking_sprite/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backends/bevy_picking_sprite/src/lib.rs b/backends/bevy_picking_sprite/src/lib.rs index 1d6f799c..1df0f355 100644 --- a/backends/bevy_picking_sprite/src/lib.rs +++ b/backends/bevy_picking_sprite/src/lib.rs @@ -81,7 +81,13 @@ pub fn sprite_picking( continue; }; - let Some(cursor_pos_world) = camera.viewport_to_world_2d(cam_transform, location.position) + let viewport_pos = camera + .logical_viewport_rect() + .map(|v| v.min) + .unwrap_or_default(); + let pos_in_viewport = location.position - viewport_pos; + + let Some(cursor_pos_world) = camera.viewport_to_world_2d(cam_transform, pos_in_viewport) else { continue; };