Skip to content

Commit d797a29

Browse files
allow accessing entity from intersections callback (#966)
# Objective Adds a new parameter to the callback in `MoveAndSlide::intersections`, to allow accessing the intersected entity. ## Solution Adds a new parameter to the relevant callback. ## Testing The change is extremely simple so as long as the logic is correct, it shouldn't need extensive testing. I ran `cargo test` to try and catch all places that needed to be updated in the repo, and use the same logic in a vendored version of the function in a project and it has worked correctly so far. I did see 4 failures in the `cargo test` but they seemed to be minor precision issues; float equality comparisons off by 0.0001 or so. Probably unrelated to the changes in this PR. --------- Co-authored-by: Joona Aalto <jondolf.dev@gmail.com>
1 parent 2b3127c commit d797a29

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

migration-guides/0.6-to-main.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ since the latest release. These guides are evolving and may not be polished yet.
66
See [migration-guides/README.md](./README.md) and existing entries for information about Avian's
77
migration guide process and what to put here.
88

9+
## Move and Slide Intersections
10+
11+
The callback provided to `MoveAndSlide::intersections` now takes a third parameter, `Entity`. This
12+
allows accessing the entity being intersected per callback. Existing calls to this function can
13+
simply ignore the new parameter with `_`.
14+
915
## `SpatialQueryPlugin` schedule is configurable
1016

1117
Similar to many other plugins, the `SpatialQueryPlugin` now stores a schedule label,

src/character_controller/move_and_slide.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ impl<'w, 's> MoveAndSlide<'w, 's> {
578578
// Depenetration still uses just the normal skin width.
579579
skin_width * 2.0,
580580
filter,
581-
|contact_point, mut normal| {
581+
|_, contact_point, mut normal| {
582582
// Check if this plane is nearly parallel to an existing one.
583583
// This can help prune redundant planes for velocity clipping.
584584
for existing_normal in planes.iter_mut() {
@@ -922,7 +922,7 @@ impl<'w, 's> MoveAndSlide<'w, 's> {
922922
shape_rotation,
923923
self.length_unit.0 * config.skin_width,
924924
filter,
925-
|contact_point, normal| {
925+
|_, contact_point, normal| {
926926
intersections.push((
927927
normal,
928928
contact_point.penetration + self.length_unit.0 * config.skin_width,
@@ -997,7 +997,7 @@ impl<'w, 's> MoveAndSlide<'w, 's> {
997997
)]
998998
/// config.skin_width,
999999
/// &filter,
1000-
/// |contact_point, normal| {
1000+
/// |_entity, contact_point, normal| {
10011001
/// intersections.push((normal, contact_point.penetration + config.skin_width));
10021002
/// true
10031003
/// },
@@ -1073,7 +1073,7 @@ impl<'w, 's> MoveAndSlide<'w, 's> {
10731073
shape_rotation: RotationValue,
10741074
prediction_distance: Scalar,
10751075
filter: &SpatialQueryFilter,
1076-
mut callback: impl FnMut(&ContactPoint, Dir) -> bool,
1076+
mut callback: impl FnMut(Entity, &ContactPoint, Dir) -> bool,
10771077
) {
10781078
let expanded_aabb = shape
10791079
.aabb(shape_position, shape_rotation)
@@ -1110,7 +1110,7 @@ impl<'w, 's> MoveAndSlide<'w, 's> {
11101110

11111111
let normal = Dir::new_unchecked(-manifold.normal.f32());
11121112

1113-
if !callback(deepest, normal) {
1113+
if !callback(intersection_entity, deepest, normal) {
11141114
// Abort further processing.
11151115
break 'outer;
11161116
}

0 commit comments

Comments
 (0)