diff options
-rw-r--r-- | src/client.rs | 26 |
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 |