diff --git a/voxygen/src/session/mod.rs b/voxygen/src/session/mod.rs index c64f885aa2..37561f0f65 100644 --- a/voxygen/src/session/mod.rs +++ b/voxygen/src/session/mod.rs @@ -1359,25 +1359,21 @@ impl PlayState for SessionState { let entity_ray_end = ray_start + cam_dir * 500.0; let terrain_ray_end = ray_start + cam_dir * 1000.0; - let aim_point = match ray_entities( - &client, - ray_start, - entity_ray_end, - 500.0, - ) { - Some((dist, _)) => ray_start + cam_dir * dist, - None => { - let terrain_ray_distance = client - .state() - .terrain() - .ray(ray_start, terrain_ray_end) - .max_iter(1000) - .until(Block::is_solid) - .cast() - .0; - ray_start + cam_dir * terrain_ray_distance - }, - }; + let aim_point = + match ray_entities(&client, ray_start, entity_ray_end, 500.0) { + Some((dist, _)) => ray_start + cam_dir * dist, + None => { + let terrain_ray_distance = client + .state() + .terrain() + .ray(ray_start, terrain_ray_end) + .max_iter(1000) + .until(Block::is_solid) + .cast() + .0; + ray_start + cam_dir * terrain_ray_distance + }, + }; // Get player orientation let ori = client diff --git a/voxygen/src/session/target.rs b/voxygen/src/session/target.rs index 5256577840..70fd3c015a 100644 --- a/voxygen/src/session/target.rs +++ b/voxygen/src/session/target.rs @@ -257,24 +257,24 @@ pub(super) fn ray_entities( ) .join() .filter(|(e, _, _)| *e != player_entity) - .filter_map(|(e, p, c)| { + .map(|(e, p, c)| { let height = c.get_height(); let radius = c.bounding_radius().max(height / 2.0); // Move position up from the feet let pos = Vec3::new(p.0.x, p.0.y, p.0.z + c.get_z_limits(1.0).0 + height/2.0); // Distance squared from start to the entity let dist_sqr = pos.distance_squared(start); - Some((e, pos, radius, dist_sqr, c)) + (e, pos, radius, dist_sqr, c) }) // Roughly filter out entities farther than ray distance - .filter(|(_, _, _, d_sqr, c)| *d_sqr <= cast_dist.powi(2)) + .filter(|(_, _, _, d_sqr, _)| *d_sqr <= cast_dist.powi(2)) .collect::>(); // Sort by distance nearby.sort_unstable_by(|a, b| a.3.partial_cmp(&b.3).unwrap()); let seg_ray = LineSegment3 { start, end }; - let entity = nearby.iter().find_map(|(e, p, r, d_sqr, c)| { + let entity = nearby.iter().find_map(|(e, p, r, _, c)| { let nearest = seg_ray.projected_point(*p); return match c { @@ -336,7 +336,7 @@ pub(super) fn ray_entities( }; }); - return entity; + entity } // Get closest point between 2 line segments https://math.stackexchange.com/a/4289668