ITADN

Ray cast goes through collider without hit

#940OpendaBlesr 创建于 2026-02-05
A-Spatial-Query
D
daBlesrcommented
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. <img width="709" height="379" alt="Image" src="https://github.com/user-attachments/assets/417846f3-f060-49f5-878c-3edd7521ea65" /> 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. <img width="804" height="369" alt="Image" src="https://github.com/user-attachments/assets/64bfd2e4-e589-40de-9e98-a051abf9f330" /> 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. https://github.com/user-attachments/assets/d862de0f-dc0c-4c16-be0b-de6f4df069aa
2 条评论