Mini Golf Challenge 2

I'm following the tutorial here: Mini Golf: Fling, TouchUp, TouchDown Gestures for App Inventor 2 to create a mini golf game. I'm having trouble with Challenge 2: "There is a slight bug when the ball hits the vertical sides of obstacle. Figure out how to program the ball to obstacle collision so that it bounces the way you would expect when the ball hits the vertical sides."
I've tried several approaches but I can never completely fix this bug. Any ideas?

This sample doc and app has bounce angle calculations that might help you ...

Alternatively, you could use an if/then/elseif ladder to test which edge of the obstacle was hit, by comparing the center of the Ball with each of the 4 edges of that obstacle:

  • x less than left x of the obstacle
  • x greater than right x of the obstacle
  • y less than the top y of the obstacle
  • y greater than the y of the bottom edhe of the obstacle.

Each of those 4 cases would require the ball to act like it was bouncing off a different edge.
(I have not tried using the AI2 bounce call for this. If that does not work, you would have to use some angle math.)

P.S. The bounce angle works okay if you specify the proper edge numbers:

Missing the obstacle can result from the Ball zipping past it due to an oversized Interval.
I got smoother motion and less skips over obstacles by reducing my Ball Interval:

Golf Ball Interval

For fun, try switching the sign of the change to the Golf Ball speed in the Clock Timer event. It speeds up the ball instead of slowing it down, making the game shorter and more exciting.
Do not allow the ball to reach transluminal speeds, lest you attract the attention of interstellar neighbors.