diff --git a/src/camera.rs b/src/camera.rs index 3cf6f6d..531b52f 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -140,11 +140,15 @@ fn update( let max_distance = camera.distance; let filter = SpatialQueryFilter::from_mask(LayerMask(GameLayer::Level.to_bits())); - let cam_pos = if let Some(first_hit) = - spatial_query.cast_ray(target, direction, max_distance, false, &filter) - { - //TODO: maybe shape casting a sphere would be better - let distance = first_hit.distance * 0.9; + let cam_pos = if let Some(first_hit) = spatial_query.cast_shape( + &Collider::sphere(0.5), + target, + Quat::IDENTITY, + direction, + &ShapeCastConfig::from_max_distance(max_distance), + &filter, + ) { + let distance = first_hit.distance; target + (direction * distance) } else { target + (direction * camera.distance)