How Hyperbole handles unlimited physics spheres


A basic game mechanic of Hyperbole is the ability to shoot an unlimited amount of balls. It's a core pillar of the design that we never want the player to feel any limitation in the amount of balls they can fire. So when we started this game and we selected Unity as the game engine, we did some testing to see what the physics and rendering engine could handle, because memory, CPU and GPU are not unlimited. It turns out that Unity handles this quite well already out of the box!

For the rendering part, once we turned on GPU instancing on the ball prefab, we could render as many spheres as we wanted. The bottleneck of the physics engine was reached long before the GPU got strained, so we were good there. The physics engine held up better than expected. In fact, we can handle up to 5000 balls in the scene at 60 fps on the main testing laptop (a 4 year old mid-range gaming laptop). Once we go over that number, things start to slow down. (note: we are very curious to try this on a modern console! We suspect we can go quite a bit higher there!)

So how did we manage to let the player have unlimited balls then? Well, we don't. As all games do, we cheat. Once the number of balls in the scene goes over 5000, we start removing balls to keep things manageable. The trick to make sure the gamer does not notice is by doing this intelligently. To do this, we iterate over all balls and assign each a score, based on various characteristics. Once all balls are scored, the highest scoring ones are removed until only 5000 exist. Scoring is done as follows:

  • distance (farther away = higher score) (we obviously use the squared distance to avoid doing 5000 square root calculations)
  • sleeping (so not moving in the physics world at the moment scores higher)
  • if moving, how fast (really slowly moving balls score higher; fast balls are important to keep, but slowly creeping balls at the bottom of pile less so)
  • visible (balls not in the view frustrum score high)

All these scores are added together into a final score. Balls with the highest scores are removed first.

To keep it all from jittering and slowing down the actual game, the gathering of balls, calculating the various scores and removing highest scoring balls are spread out over multiple frames using a CoRoutine with a lot of different steps.

In the end, it works quite well. 5000 balls in a scene looks very impressive for the player, and we have yet to see any ball disappear in front of us, so the illusion seems to hold up!


Let us know if you want to learn about any other part of the game!

Get Hyperbole

Leave a comment

Log in with itch.io to leave a comment.