dimforge / bevy_rapier

Official Rapier plugin for the Bevy game engine.
https://rapier.rs
Apache License 2.0
1.2k stars 257 forks source link

Does Rapier 3d Implement Spatial Partitioning? #507

Closed AndrewCS149 closed 2 months ago

AndrewCS149 commented 2 months ago

Scenario

I have a simple program that employs 1000 units on screen. Each unit has its own dynamic rigidbody, as well as a collider. On startup, these units are spaced far enough apart that they are not colliding. My program runs at a very slow 15 FPS, and when the units actually start colliding, it drops to below 5 FPS.

From my understanding, collision happens in two phases, the Broadphase & Narrowphase. The Broadphase checks to see if there are any collisions or intersections, while the narrowphase uses the data from the broadphase to actually compute the contact points required for actual collision.

Because of the exponentially bad performance as I increase the amount of units on screen, I would assume that spatial Partitioning is not implemented.

Questions

Vrixyz commented 2 months ago

Short answer: yes, rapier3d has space partitionning.

Slightly longer response is that the broadphase setups the space partitioning and the narrowphase does the finer detection. On top of that there is an IslandManager to be able to parallelize these 2 steps better.

This repository is focused on bevy integration though, and I feel like your question is more oriented towards "lower level" performance: Consider looking into the lower level crates such as rapier or Parry.

If you have a particular performance issue, double check you're running in release mode (or your dependency is), as mentioned in the documentation.

If you still have a problem, please reopen an issue! Minimal reproducible examples are appreciated :)