Skip to content

Commit

Permalink
fix: Avoid physics query slowdown over time by rebuilding broadphase
Browse files Browse the repository at this point in the history
every frame
  • Loading branch information
MaxCWhitehead committed Apr 6, 2024
1 parent d89e045 commit c2c0b65
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/physics/collisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,13 @@ impl<'a> CollisionWorld<'a> {
&collision_cache,
);

// Force a full rebuild of broadphase
// PhysicsPipeline step should incrementally update it, but due to an issue with
// incrementally rebalancing BVH in parry2d, the tree becomes unbalanced and query perf tanks.
// Rebuilding it every frame is quite fast for our game, and avoids this issue.
// https://github.com/fishfolk/jumpy/issues/961
query_pipeline.update(rigid_body_set, collider_set);

// Iter on each dynamic rigid-bodies that moved.
for rigid_body_handle in islands.active_dynamic_bodies() {
let rigid_body = rigid_body_set.get_mut(*rigid_body_handle).unwrap();
Expand Down

0 comments on commit c2c0b65

Please sign in to comment.