From 465a5d21effb4bb6503aa6a999209ff76de1bc82 Mon Sep 17 00:00:00 2001 From: Yang Zhou Date: Fri, 10 Jan 2025 15:22:50 -0500 Subject: [PATCH] [FIX] (cu_rp_balancebot) fix drag direction for any camera view (#207) --- examples/cu_rp_balancebot/src/world/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/cu_rp_balancebot/src/world/mod.rs b/examples/cu_rp_balancebot/src/world/mod.rs index 0378fe56c..2e74bfafd 100644 --- a/examples/cu_rp_balancebot/src/world/mod.rs +++ b/examples/cu_rp_balancebot/src/world/mod.rs @@ -315,6 +315,7 @@ fn global_cart_drag_listener( mut drag_events: EventReader>, parents: Query<(&Parent, Option<&Cart>)>, mut transforms: Query<&mut Transform, With>, + camera_query: Query<&Transform, (With, Without)>, // Add Without to prevent conflicts ) { for drag in drag_events.read() { if drag.button != PointerButton::Primary { @@ -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; } } }