aevyrie / bevy_mod_picking

Picking and pointer events for Bevy.
https://crates.io/crates/bevy_mod_picking
Apache License 2.0
791 stars 174 forks source link

Drag delta not supported with camera scaling_mode #287

Closed tpuric closed 11 months ago

tpuric commented 11 months ago

Drag delta not supported with camera scaling_mode.

When adding scaling_mode to the camera, the delta is off by the scale factor as shown in the demo below. Interaction features (hover, select, deselect) all work as expected

https://github.com/aevyrie/bevy_mod_picking/assets/137123546/8600afa3-f3f3-4e81-9eb4-5fd75e0e0355

You can replicate this behaviour by switching the camera in the drag_and_drop example with what's shown below.

    commands.spawn(Camera2dBundle {
        projection: OrthographicProjection {
            far: 100.,
            near: -100.,
            scaling_mode: ScalingMode::AutoMin {
                min_width: 512.,
                min_height: 288.
            },
            ..default()
        },
        ..default()
    });

Current workaround is to adjust the delta by the scale factor or utilise another mechanism. I am new to the library, so there may be some other configuration to adjust that I haven't come across. Love the library, very nicely done :)

jthacker commented 9 months ago

@tpuric Why did you close this? This does seem like something that should be resolved or at least an official response on how to handle it. I was also impacted by this.

musjj commented 9 months ago

Yeah, I'm also facing this issue too, I think this should be re-opened. Should I make a new issue?

jthacker commented 9 months ago

Related https://github.com/aevyrie/bevy_mod_picking/issues/244#issuecomment-1689539413

Seems like this is known and perhaps expected.

Easy enough workaround though with a single camera.

fn update_handle_drag(
    mut events: EventReader<Pointer<Drag>>,
    mut query: Query<&mut Transform>,
    query_projection: Query<&OrthographicProjection>,
) {
    let projection = query_projection.single();
    for event in events.read() {
        let mut transform = query.get_mut(event.target).unwrap();
        let scaled_delta = event.delta * projection.scale;
        transform.translation.x += scaled_delta.x;
        transform.translation.y -= scaled_delta.y;
    }
}
aevyrie commented 8 months ago

The delta from a drag is intended to pass through the input values, with no modification. The example in repo simply doesn't handle any of this logic.

animaone commented 1 month ago

Related #244 (comment)

Seems like this is known and perhaps expected.

Easy enough workaround though with a single camera.

fn update_handle_drag(
    mut events: EventReader<Pointer<Drag>>,
    mut query: Query<&mut Transform>,
    query_projection: Query<&OrthographicProjection>,
) {
    let projection = query_projection.single();
    for event in events.read() {
        let mut transform = query.get_mut(event.target).unwrap();
        let scaled_delta = event.delta * projection.scale;
        transform.translation.x += scaled_delta.x;
        transform.translation.y -= scaled_delta.y;
    }
}

Nice! Thank you! It works!