Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix raycast issue #43

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/rapier2d-wrapper/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,16 @@ pub extern "C" fn intersect_ray(world_handle : Handle, pixel_from : &Vector, dir
filter.predicate = Some(&predicate);

let mut result = false;
let mut length_current = Real::MAX;
physics_world.query_pipeline.intersections_with_ray(&physics_world.rigid_body_set, &physics_world.collider_set, &ray, length, solid, filter,
|handle, intersection| {
// Find closest intersection
if intersection.toi > length_current {
return true;
}
// Callback called on each collider hit by the ray.

if hit_from_inside || intersection.toi != 0.0 {
length_current = intersection.toi;
result = true;

let hit_point = ray.point_at(intersection.toi);
Expand All @@ -152,7 +157,7 @@ pub extern "C" fn intersect_ray(world_handle : Handle, pixel_from : &Vector, dir
};
hit_info.collider = collider_handle_to_handle(handle);
hit_info.user_data = physics_world.get_collider_user_data(handle);
return false; // We found a collision hit.
//return false; // We found a collision hit.
}
true // Continue to search.
},
Expand Down
Loading