freezy / VisualPinball.Engine

:video_game: Visual Pinball Engine for Unity
https://docs.visualpinball.org
GNU General Public License v3.0
415 stars 62 forks source link

Detect stuck balls #480

Open arthurkehrwald opened 1 month ago

arthurkehrwald commented 1 month ago

Problem

Inevitably, the ball will get stuck occasionally. Sometimes due to the physics engine, sometimes due to an oversight in the table design. It would be good to have some kind of reset mechanism when this happens. There are two problems here: Detecting when a ball gets stuck, and making it 'unstuck'.

Detection

The easiest solution I can think of would be to check whether the ball is moving around. The algorithm would go something like this:

  1. Record the ball's position x times per second
  2. Check if distance between the two furthest apart points recorded in the past y seconds exceeds threshold z
  3. Also check if the player is holding down a flipper button or, alternatively, if the ball is in contact with a flipper. This ensures the ball won't be reset when held by a flipper. The only problem I see with this is that it could still lead to false positives when table authors trap balls in the play field intentionally. Maybe we could allow author's to place triggers that suspend stuck detection for any balls inside.

Resolution

Teleport the ball back to the exit kicker and eject it into the plunger lane. Log a warning to communicate what just happened to the table author.