This is a short blog that describes the flipper and ball physics configuration for Hyperspace Pinball on Steam which you can download at http://store.steampowered.com/app/349020 . It was done a certain way before Unity 5; but since upgrading, I had to make a number of changes to have the game work again. Keep in mind the combination of values I use are tweaked for my specific game.

Physics

 

Ball

 

Unlike the table you're probably going to use, mine is in outer space. There is no bottom on the table for the ball to roll around on. I even made the ball not spin so that I could put a 2D texture in front of it for the mobile version. I never actually found a shader for a 3D ball that I liked!

 

Flipper

 

Notice that the collision detection is Discrete. I tried to make it Continuous Dynamic, but in that mode the ball kept getting glued to the flipper.

See my solution to the problem of the ball falling through the flipper: A collider shaped like a quarter cylinder. As the flipper rotates, the cylinder rotates accordingly. It never obstructs space it doesn't belong in, yet it maintains enough of a presence for the physics solver to know the ball should not go through it.

The disabled Fall Through Preventer Flipper script was used in older versions of Unity back when this collider was a trigger and I wrote my own code to push the ball back up. I remember trying a non-trigger collider at first but the ball went through it; I gave up trying to figure out why back in the day.

 

 

Flipper Activation

Each flipper is controlled by a script that has a flag called isGoingToPressedRotation. When the player presses a button to make a flipper spin up, that flag is set to true. When the button is released, it becomes false. The following MonoBehaviour event actually does the movement:

 

 

Currently, PinballPhysics.FlipperStrength is 80000 which provides for a rapid spin. The 40000 "magic number" is a relic of past experimenting with flipper strength which I never went back and cleaned up. 

 

Choosing the Values

How did I get to the values I did? To be honest, I just tried different values until it all worked.

 

Physics Tips

  • Ensure all non-moving objects are flagged as Static
  • Be sure to use Continuous or Continuous Dynamic collision detection on the ball since it will be moving fast
  • Make a test scene that exercises the game flippers automatically to detect ball fall-through. Playing the table manually is just not sufficient alone.
  • Either avoid having razor thin walls in your table, or rigorously ensure the ball cannot go through them by making a test scene.