-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed as duplicate of#18005
Closed as duplicate of#18005
Copy link
Labels
C-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorC-ExamplesAn addition or correction to our examplesAn addition or correction to our examples
Description
Bevy version
0.16.0
What you did
Used sprite picking with custom viewport
Camera {
viewport: Some(Viewport {
physical_position: (window_size * 0.125).as_uvec2(),
physical_size: (window_size * 0.75).as_uvec2(),
..default()
}),
..default()
},What went wrong
- pointer coordinate in sprite picking is incorrect. A sprite is picked in the wrong position.
Potential fix
Sprite picking code subtracts viewport min from cursor coordinate:
bevy/crates/bevy_sprite/src/picking_backend.rs
Lines 143 to 151 in cd67bac
| 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; | |
| }; |
However 2d_viewport_to_world example does not.
bevy/examples/2d/2d_viewport_to_world.rs
Lines 35 to 42 in cd67bac
| let Some(cursor_position) = window.cursor_position() else { | |
| return; | |
| }; | |
| // Calculate a world position based on the cursor's position. | |
| let Ok(world_pos) = camera.viewport_to_world_2d(camera_transform, cursor_position) else { | |
| return; | |
| }; |
If I remove the subtraction from sprite picking code as well, it seems to work correctly. (it is redundant as Camera::viewport_to_world already does?)
Metadata
Metadata
Assignees
Labels
C-BugAn unexpected or incorrect behaviorAn unexpected or incorrect behaviorC-ExamplesAn addition or correction to our examplesAn addition or correction to our examples


