Skip to content

Commit

Permalink
[FIX] (cu_rp_balancebot) fix drag direction for any camera view (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
makeecat authored Jan 10, 2025
1 parent f62efb8 commit 465a5d2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion examples/cu_rp_balancebot/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ fn global_cart_drag_listener(
mut drag_events: EventReader<Pointer<Drag>>,
parents: Query<(&Parent, Option<&Cart>)>,
mut transforms: Query<&mut Transform, With<Cart>>,
camera_query: Query<&Transform, (With<Camera>, Without<Cart>)>, // Add Without<Cart> to prevent conflicts
) {
for drag in drag_events.read() {
if drag.button != PointerButton::Primary {
Expand All @@ -329,7 +330,10 @@ fn global_cart_drag_listener(
}

if let Ok(mut root_transform) = transforms.get_mut(entity) {
root_transform.translation.x += drag.delta.x / 500.0;
let direction_multiplier = camera_query.iter().next().map_or(1.0, |camera_transform| {
-camera_transform.forward().z.signum()
});
root_transform.translation.x += direction_multiplier * drag.delta.x / 500.0;
}
}
}
Expand Down

0 comments on commit 465a5d2

Please sign in to comment.