Skip to content

Commit

Permalink
Explicitly count static colliders as inactive in broad phase (Jondolf…
Browse files Browse the repository at this point in the history
…#283)

# Objective

Currently, the broad phase determines whether a body is inactive just by checking if the position or rotation has changed. If a static body is moved, it will unnecessarily check collisions against other static bodies. This can cause performance issues with e.g. floating point worlds where all entities are frequently moved.

## Solution

Also check whether the body is static in the `update_aabb_intervals` system.
  • Loading branch information
Jondolf authored Dec 27, 2023
1 parent db22413 commit 8c00e09
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/plugins/collision/broad_phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ impl MapEntities for AabbIntervals {
#[allow(clippy::type_complexity)]
fn update_aabb_intervals(
aabbs: Query<(
&RigidBody,
&ColliderAabb,
&ColliderParent,
Option<&CollisionLayers>,
Expand All @@ -194,13 +195,13 @@ fn update_aabb_intervals(
) {
intervals.0.retain_mut(
|(collider_entity, collider_parent, aabb, layers, is_inactive)| {
if let Ok((new_aabb, new_parent, new_layers, position, rotation)) =
if let Ok((rb, 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();
*is_inactive = (!position.is_changed() && !rotation.is_changed()) || rb.is_static();
true
} else {
false
Expand Down

0 comments on commit 8c00e09

Please sign in to comment.