From 2f0309dd9c3cca605529a3bacf19cbffd60f0948 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Thu, 28 Dec 2023 15:00:20 +0200 Subject: [PATCH] Fix static body handling in `update_aabb_intervals` (#285) # Objective #283 had an oversight where it required colliders to have a `RigidBody` for AABBs to be updated. It also didn't handle child colliders. ## Solution Use the `ColliderParent` to get the (optional) `RigidBody` of the entity the collider is attached to. --- src/plugins/collision/broad_phase.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plugins/collision/broad_phase.rs b/src/plugins/collision/broad_phase.rs index 45ff3568..d1676f4b 100644 --- a/src/plugins/collision/broad_phase.rs +++ b/src/plugins/collision/broad_phase.rs @@ -184,24 +184,27 @@ impl MapEntities for AabbIntervals { #[allow(clippy::type_complexity)] fn update_aabb_intervals( aabbs: Query<( - &RigidBody, &ColliderAabb, &ColliderParent, Option<&CollisionLayers>, Ref, Ref, )>, + rbs: Query<&RigidBody>, mut intervals: ResMut, ) { intervals.0.retain_mut( |(collider_entity, collider_parent, aabb, layers, is_inactive)| { - if let Ok((rb, new_aabb, new_parent, new_layers, position, rotation)) = + if let Ok((new_aabb, new_parent, new_layers, position, rotation)) = aabbs.get(*collider_entity) { *aabb = *new_aabb; *collider_parent = *new_parent; *layers = new_layers.map_or(CollisionLayers::default(), |layers| *layers); - *is_inactive = (!position.is_changed() && !rotation.is_changed()) || rb.is_static(); + + let is_static = rbs.get(new_parent.get()).is_ok_and(RigidBody::is_static); + *is_inactive = is_static || (!position.is_changed() && !rotation.is_changed()); + true } else { false