Skip to content

Commit

Permalink
Fix sprite picking backend not considering the viewport of the camera.
Browse files Browse the repository at this point in the history
Without this, the pointer is offset from the visuals based on where the viewport is. Now it's fixed!

Co-authored-by: johanhelsing <[email protected]>
  • Loading branch information
andriyDev and johanhelsing committed Nov 14, 2024
1 parent aab36f3 commit 35c9cef
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/bevy_sprite/src/picking_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ pub fn sprite_picking(
continue;
};

let Ok(cursor_ray_world) = camera.viewport_to_world(cam_transform, location.position)
else {
let viewport_pos = camera
.logical_viewport_rect()
.map(|v| v.min)
.unwrap_or_default();
let pos_in_viewport = location.position - viewport_pos;

let Ok(cursor_ray_world) = camera.viewport_to_world(cam_transform, pos_in_viewport) else {
continue;
};
let cursor_ray_len = cam_ortho.far - cam_ortho.near;
Expand Down

0 comments on commit 35c9cef

Please sign in to comment.