Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice

Question Pinball physics with Rigidbodies

Discussion in 'Physics' started by Caliber, Jul 31, 2023.

  1. Caliber

    Caliber

    Joined:
    Feb 11, 2018
    Posts:
    86
    My game uses rigidbodies and there is a pinball component. Since rigidbodies work fine for all the other mechanics, I'd prefer to not implement my own physics system. But I'm having issues with the flippers interacting with the ball. If the flipper launches the ball at a certain distance from the rotation point, the ball takes a weird trajectory.

    The flippers are hinge joints.
    Both the ball and flippers have Continuous Dynamic collision detection (speculative on ball caused some weird interactions).
    All parts (flipper, ball, wall, floors) have separate physics materials, but changing friction/bounciness didn't solve the issue.

    I set up a test scene with a debug script, dropping the ball from two separate position (red & yellow), which gives the ball different speed when it touches the flipper, and then launch the ball at different positions.





    Any ideas?
     
  2. Caliber

    Caliber

    Joined:
    Feb 11, 2018
    Posts:
    86
    That was my idea as well, but as I mentioned in OP, changing friction/bounciness didn't help noticeably. (It did change the trajectories of the ball, but the anomalies remained, just occurred at different points)

    The speed of the ball is changed by having two different spawn points for red & yellow (can be seen in the video). The physics handle the rest. I just chose two semi-random spawn points.
     
    Last edited: Aug 1, 2023
  3. MidnightGameDeveloper

    MidnightGameDeveloper

    Joined:
    Apr 26, 2014
    Posts:
    122
    Have you ever found a solution to this problem?
     
  4. Caliber

    Caliber

    Joined:
    Feb 11, 2018
    Posts:
    86
    Not an actual solution using Rigidbodies, just a workaround.
    Basically, when I press the flipper, I store the ball's velocity, enable isKinematic and parent the ball to the flipper. Then when the flipper reaches the end position, I unparent the ball from the flipper, disable isKinematic and calculate a force, using the stored velocity and the ball's distance from the rotation point of the flipper, which I apply to the ball.
    A bit messy, but works.
     
    Last edited: Mar 6, 2024