Skip to content

Ray cast goes through collider without hit #940

@daBlesr

Description

@daBlesr

Hello,

I have been trying to check if an entity is visible or is blocked by a structure by casting a ray.

if let Some(hits) = spatial_query.cast_ray(
    eyes_pos,
    Dir3::new(target_pos - eyes_pos).unwrap_or(Dir3::NEG_Z),
    15.0,
    true,
    &SpatialQueryFilter::default()
            .with_excluded_entities([archer_entity])
            .with_mask([Layer::Structure, Layer::Player]),
) {
    println!("hit entities {:?}",  name_query.get(hits.entity));
}

However, the ray goes through the wall and has a hit with the other archer.
Image
How I set up my wall:

commands.spawn((
    Structure,
    Name::new("Wall"),
    SceneRoot(wall_model.0.clone()),
    Transform::from_translation(*loc)
        .with_rotation(Quat::from_axis_angle(Vec3::Y, PI / 2.0)),
    RigidBody::Static,
    CollisionMargin(0.1),
    SweptCcd::default(),
    // Collider::cuboid(1.0, 2.0, 1.0),
    ColliderConstructorHierarchy::new(ColliderConstructor::ConvexDecompositionFromMesh),
    CollisionLayers::new(Layer::Structure, LayerMask::ALL),
));

If use Collider::cuboid(1.0, 2.0, 1.0), it does have an intersection with the ray. But I am importing a scene from blender with many objects so I can't create a custom primitive for each entity.

I have also tried all possible ColliderConstructors from Meshes, TrimeshFromMesh, ColliderConstructor::VoxelizedTrimeshFromMesh { voxel_size: 0.1, fill_mode: FillMode::SurfaceOnly }), with different settings and none worked. Even ColliderConstructorHierarchy::new(ColliderConstructor::VoxelizedTrimeshFromMesh { voxel_size: 0.3, fill_mode: FillMode::FloodFill { detect_cavities: false} }) does not detect ray casts even though the collission looks perfectly abstracted to me.
Image

I have also tried spatial_query.cast_shape with small and large spheres and spatial_query.shape_intersections with a a long capsule from eye to eye through the wall, and I have also checked directly if the structure it self is on a ray by using collider.intersects_ray. None of these return an intersection with the wall.

Important note, if I shoot an arrow however at wall, the wall does block the arrow, see video.

Schermopname.2026-02-05.om.10.50.29.mov

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-Spatial-QueryRelates to spatial queries, such as ray casting, shape casting, and intersection tests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions