shapecast for camera pos

This commit is contained in:
2025-04-13 21:41:25 +02:00
parent ca9211d0d1
commit 33ddac2f18

View File

@@ -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)