determine closeness based on distance to surface, not center

This commit is contained in:
yuni 2024-04-16 01:54:34 +02:00
parent a66660cb44
commit 6002688bb4

View file

@ -405,11 +405,12 @@ pub fn find_closest_target<TargetSpecifier>(
// 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);
}
}