Skip to content

Commit

Permalink
Fix static body handling in update_aabb_intervals (#285)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
Jondolf authored Dec 28, 2023
1 parent 370354f commit 2f0309d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/plugins/collision/broad_phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,27 @@ impl MapEntities for AabbIntervals {
#[allow(clippy::type_complexity)]
fn update_aabb_intervals(
aabbs: Query<(
&RigidBody,
&ColliderAabb,
&ColliderParent,
Option<&CollisionLayers>,
Ref<Position>,
Ref<Rotation>,
)>,
rbs: Query<&RigidBody>,
mut intervals: ResMut<AabbIntervals>,
) {
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
Expand Down

0 comments on commit 2f0309d

Please sign in to comment.