Background As a side project a friend and I have been developing a solar system simulation for the vive. We are using the Steam VR plugin. We are targetting 64bit PCs and the Vive. We have created our own scripts to create a point based gravity system that enables us to define a gravitational force centered on any game object of our choosing. The simulation starts with a single gravity well existing in the scene and the user can add items to the scene of various masses and velocities and watch them interact with the gravity well.
Problem We can get up to about 500+ active rigidbodies (all using primitive sphere colliders) before things begin to slow down. Every fixed update we gather the gravitational force that needs to be applied to these rigidbodies and then use addforce to adjust their trajectories accordingly. To be honest this works just fine for what we want but for our next step we begin to run into serious problems. I.E. Ideally instead of a single gravitational source (the “star” in the center of the scene) we want ALL rigidbodies in the scene to also have their own gravity, based off of their mass. Our current scripts allow for this, but turning this functionality on causes a huge drop in the number of items we can have in our scene before slowdown. We drop down to about 100-150 and even then it can be problematic. It is pretty obvious what’s happening, both in theory and from the profiler- the evaluations we are doing balloon to a huge number because now we are evaluating the amount of force to add, multiplied by the number of items in the scene, for each individual rigidbody.
Question Can anyone point me in the right direction on how to possibly optimize a scene like this? I would like to get back to about 500 active rigidbodies if possible, while allowing all these items to have their own gravity as well. The ideal scenario would be to observe these items coalescing into “chunks” in the same way planetary bodies accrue from masses of smaller particles circling a gravity well. I am doing what research I can, but in actuality I am an animator and artist who dabbles in programming so any assistance would be a great help (currently trying research and learn if it would be possible to somehow offload all these calculations to the gpu).
Apologies for the wall of text, I can provide messy samples of code if you like. Thanks for reading.