Skip to content

Commit

Permalink
fixed dynamic behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
clinuxrulz committed Feb 19, 2024
1 parent 49bef25 commit fb9fae2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ pub fn update_input<S: VirtualJoystickID>(
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 {
Expand Down Expand Up @@ -109,7 +108,6 @@ pub fn update_input<S: VirtualJoystickID>(
continue;
}
knob.id_drag = None;
knob.base_pos = Vec2::ZERO;
knob.start_pos = Vec2::ZERO;
knob.current_pos = Vec2::ZERO;
knob.delta = Vec2::ZERO;
Expand Down
1 change: 0 additions & 1 deletion src/ui/bundles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ pub struct VirtualJoystickNode<S: VirtualJoystickID> {
pub struct VirtualJoystickData {
pub id_drag: Option<u64>,
pub dead_zone: f32,
pub base_pos: Vec2,
pub start_pos: Vec2,
pub current_pos: Vec2,
pub delta: Vec2,
Expand Down
12 changes: 9 additions & 3 deletions src/ui/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ pub fn extract_joystick_node<S: VirtualJoystickID>(
|| !view_visibility.get()
|| uinode.size().x == 0.
|| uinode.size().y == 0.
|| data.id_drag.is_none() && joystick_node.behaviour == VirtualJoystickType::Dynamic
{
continue;
}
Expand Down Expand Up @@ -72,7 +71,6 @@ pub fn extract_joystick_node<S: VirtualJoystickID>(
|| !view_visibility.get()
|| uinode.size().x == 0.
|| uinode.size().y == 0.
|| data.id_drag.is_none() && joystick_node.behaviour == VirtualJoystickType::Dynamic
{
continue;
}
Expand Down Expand Up @@ -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.)
}
},
}
}

0 comments on commit fb9fae2

Please sign in to comment.