Physics with lots of bodies performance question

Hi all.
I am now at a point where my scene is starting to have a few hundred rigid bodies for things like trees, rocks, bushes, stumps, enemies, etc.

I want to here from the community how or what is the best way to handle this in a game?

My thinking is to create special type of control that will check what the distance is from the camera and then enable or disable the rigidbody.

Is there maybe any other ideas or proper way to do this?

1 Like

While I don’t know bullet’s internals, I would suspect that static rigid bodies should already be pretty well optimized in broad phase.

…and if your trees/rocks/bushes/etc. are not static objects then “there’s your problem”.

Objects that don’t move and don’t “integrate” (integrate in the physics movement, etc. sense) should not have an overly high impact on a physics engine.

Aah okay nice.
I was not aware of this.
I don’t have a problem per say I was just wondering how would one skip the physics updates and check from happening and just push some more performance.
My trees, rocks, bushes, etc are static bodies.

Thanks for the reply.

Yeah, so no updates happen on static bodies.

And the “checks” part will only happen when non-static objects are close enough to them to matter.

My first suggestion is to merge all the static bodies into a single static body. I’ve done this in my closed-source project.

The first step in physics simulation (broadphase collision detection) identifies object pairs that could intersect. The CPU cost grows roughly as the square of the number objects. If half your objects are static bodies, then merging them should reduce the cost of broadphase by almost 4x.

In the general case, merging can be accomplished by creating a CompoundCollisionShape for the merged body. But if the shapes are all MeshCollisionShape, then I’d merge the meshes and generate a single MeshCollisionShape from the merged mesh.