From fb9fae2da2c1100ecfea620faef69df6de5ddf94 Mon Sep 17 00:00:00 2001 From: Clinton Selke Date: Mon, 19 Feb 2024 22:53:51 +1000 Subject: [PATCH] fixed dynamic behaviour --- src/input.rs | 2 -- src/ui/bundles.rs | 1 - src/ui/systems.rs | 12 +++++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/input.rs b/src/input.rs index e1ce94a..04cb039 100644 --- a/src/input.rs +++ b/src/input.rs @@ -81,7 +81,6 @@ pub fn update_input( knob.current_pos = *pos; let half = knob.interactable_zone_rect.half_size(); if node.behaviour == VirtualJoystickType::Dynamic { - knob.base_pos = *pos; let to_knob = knob.current_pos - knob.start_pos; let distance_to_knob = to_knob.length(); if distance_to_knob > half.x { @@ -109,7 +108,6 @@ pub fn update_input( continue; } knob.id_drag = None; - knob.base_pos = Vec2::ZERO; knob.start_pos = Vec2::ZERO; knob.current_pos = Vec2::ZERO; knob.delta = Vec2::ZERO; diff --git a/src/ui/bundles.rs b/src/ui/bundles.rs index a29f02b..d528d98 100644 --- a/src/ui/bundles.rs +++ b/src/ui/bundles.rs @@ -65,7 +65,6 @@ pub struct VirtualJoystickNode { pub struct VirtualJoystickData { pub id_drag: Option, pub dead_zone: f32, - pub base_pos: Vec2, pub start_pos: Vec2, pub current_pos: Vec2, pub delta: Vec2, diff --git a/src/ui/systems.rs b/src/ui/systems.rs index 8a57153..fe3942d 100644 --- a/src/ui/systems.rs +++ b/src/ui/systems.rs @@ -40,7 +40,6 @@ pub fn extract_joystick_node( || !view_visibility.get() || uinode.size().x == 0. || uinode.size().y == 0. - || data.id_drag.is_none() && joystick_node.behaviour == VirtualJoystickType::Dynamic { continue; } @@ -72,7 +71,6 @@ pub fn extract_joystick_node( || !view_visibility.get() || uinode.size().x == 0. || uinode.size().y == 0. - || data.id_drag.is_none() && joystick_node.behaviour == VirtualJoystickType::Dynamic { continue; } @@ -108,6 +106,14 @@ fn get_base_pos( joystick.start_pos.extend(0.) } } - VirtualJoystickType::Dynamic => joystick.base_pos.extend(0.), + VirtualJoystickType::Dynamic => { + if joystick.id_drag.is_none() { + global_transform + .compute_matrix() + .transform_point3((container_rect.center() - (uinode.size() / 2.)).extend(0.)) + } else { + joystick.start_pos.extend(0.) + } + }, } }