aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-15 16:28:01 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-15 16:35:31 +0100
commit9114f5670876223d37f8338f3acc6a45530bf654 (patch)
treec619c45237dcc5a6ed957fd7b704d9d2d793fdfa /src
parentc71366c2e0a9f0b454957feeb87b51f6b27d54bd (diff)
fix: choose closest hovered player
Diffstat (limited to 'src')
-rw-r--r--src/client.rs26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/client.rs b/src/client.rs
index fff18af..3fef179 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -184,27 +184,21 @@ fn hovered_other_player(
hoverables: &Query<(&PlayerId, &PlayerPosition)>,
windows: &Query<&Window>,
) -> Option<(PlayerId, PlayerPosition)> {
- let Some((id, position)) = hovered_player(cameras, hoverables, windows) else {
- return None;
- };
- if id.0 == client_id.0 {
- return None;
- }
- Some((id, position))
-}
-
-fn hovered_player(
- cameras: &Query<(&Camera, &GlobalTransform)>,
- hoverables: &Query<(&PlayerId, &PlayerPosition)>,
- windows: &Query<&Window>,
-) -> Option<(PlayerId, PlayerPosition)> {
let Some(world_position) = cursor_world_position(&windows, &cameras) else {
return None;
};
let mut hovered_player = None;
+ let mut hovered_distance = None;
for (id, position) in hoverables.iter() {
- if position.0.distance(world_position) < PLAYER_HOVER_RADIUS {
- hovered_player = Some((*id, *position));
+ if id.0 == client_id.0 {
+ continue;
+ }
+ let distance = position.0.distance(world_position);
+ if distance < PLAYER_HOVER_RADIUS {
+ if hovered_distance.map_or(true, |hovered_distance| distance < hovered_distance) {
+ hovered_player = Some((*id, *position));
+ hovered_distance = Some(distance);
+ }
}
}
hovered_player