3
\$\begingroup\$

I'm trying to create a pinball and flipper system in Unity.

Unity has documentation specifically on a spinning body and a ball.

I am using rigid bodies for both the ball and flipper. I've set the ball to continuous dynamic and the flipper to continuous speculative but there are still cases where the ball passes through the flipper:

Animation of ball sometimes falling through actuating flipper

I am using the basic sphere and box colliders. The flipper is using a hinge joint with 28000 force and a script that sets it to either 18000 or -18000 velocity depending on if space bar is pressed. Gravity is set to -300 Y. The ball and table have 0.01 dynamic and static friction. The ball is rolling down an inclined plane with a rotation of -8 Z. I am using Unity 2021.3.10f1.

I have tried changing default contact offset, default solver iterations, and default solver velocity iterations in the project settings but these have not fixed the issue.

\$\endgroup\$
5
  • \$\begingroup\$ Do you observe any difference if the ball is also set to use continuous speculative mode? \$\endgroup\$
    – DMGregory
    Commented Sep 28, 2022 at 19:59
  • \$\begingroup\$ The issue still happens when the ball is set to continuous speculative, additionally there are other issues with setting the ball to continuous speculative that are described in the unity docs. \$\endgroup\$
    – Will
    Commented Sep 28, 2022 at 20:17
  • 1
    \$\begingroup\$ Have you tried using a smaller time step in the project settings (Edit -> Project Settings -> Time)? Also, that ball looks a bit small for a pinball game. Do you need it to be that small? \$\endgroup\$
    – Adam
    Commented Sep 29, 2022 at 0:47
  • \$\begingroup\$ Changing the time step from 0.02 to 0.01 fixed it. Thank you \$\endgroup\$
    – Will
    Commented Sep 29, 2022 at 1:02
  • 1
    \$\begingroup\$ @Adam, want to post that suggestion as an Answer that can be upvoted / marked as Accepted? \$\endgroup\$
    – DMGregory
    Commented Sep 29, 2022 at 2:38

1 Answer 1

1
\$\begingroup\$

The problem you're having is generally called tunnelling.

There are a few ways that you can try to solve it:

  • Instead of simulating the physics in discrete steps, use some sort of continuous collision detection system. For general purpose physics, continuous collision detection can be rather expensive, and I don't know if Unity has a built in implementation.
  • Use a smaller time step, which you can do in Unity in the project settings (Edit -> Project Settings -> Time). This will make the physics simulation more expensive, as it will need to calculate more steps.
  • Try to avoid the problem by avoiding small / thin fast moving objects. For example, that pinball looks a bit on the small side in your image. Do you need it to be that small?
\$\endgroup\$
1
  • 1
    \$\begingroup\$ Increasing the size of the ball and using continuous collision did not help in this case. The time step was the solution. \$\endgroup\$
    – Will
    Commented Oct 2, 2022 at 0:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .