From 6002688bb40e1531baf16ce6fe06c15bc0179fb7 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 16 Apr 2024 01:54:34 +0200 Subject: [PATCH] determine closeness based on distance to surface, not center --- src/camera.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/camera.rs b/src/camera.rs index 2582901..ac1b20a 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -405,11 +405,12 @@ pub fn find_closest_target( // not on the player mesh but on the camera, which doesn't have a position. let (angular_diameter, angle, distance) = calc_angular_diameter_known_target_vector( trans, camera_transform, &target_vector); + let distance_to_surface = distance - trans.scale.x; if angle <= angular_diameter.clamp(0.001, PI) { // It's in the field of view! //commands.entity(entity).insert(IsTargeted); - if distance < closest_distance { - closest_distance = distance; + if distance_to_surface < closest_distance { + closest_distance = distance_to_surface; closest_entity = Some(entity); } }