Quantum tunneling effect with unbreakable blocks after adding random tweak

The randomized change in the vector seems to work for the most part, using the 0.5 setting for randomFactor, but I have seen a strange behavior twice now. I have a line unbreakable blocks below the breakable ones and twice now the ball has literally tunneled through the wall. Both times it was coming from above, but I think that is just a coincidence.

The last time I had it bouncing back and forth almost vertically, between the top of the play area and the unbreakable block line, having cleared out all the blocks in between already. You could see it go very slightly at an angle on some of the bounces and the speed changed too. Sometimes it seems to speed up (more often than not) and sometimes it goes a bit slower. One time it came down and went right through the unbreakable block and (of course) hit the lose collider.

I think the code is simulating quantum tunneling behavior in the game world! :slight_smile:

I am guessing this is because the random vector change being done makes it travel in the direction opposite of where it should go, putting it past the collider boundary of the block. The collider probably only looks for something coming from outside the boundary, so it ignores the ball when it hits the inside of the boundary on the far side of the block.

Maybe we need to provide a little more guidance to what direction we “push” the ball with our random tweak to its path?

I forgot to past an image of my screen:

One more thing to note. I have completed the Auto Play lesson and I saw the ball go through the unbreakable blocks while going up, plus it also went through the paddle (so I lost in auto mode - oh no!).

I am pretty sure this has something to do with the 2D colliders and how the random change in vector is being handled, but not sure just how.

Check if your ball’s Rigidbody2D Collision Detection is set to Continuous instead of Discrete, this should solve your issue.

Yes that did seem to solve it.

What is the difference between Discrete and Continuous? How would you know which one to choose?

Use Discrete when the object isn’t moving (but can be moved) or is moving at a somewhat slow pace.

Continuos is for more accurate calculations, meaning it will always collide with things regardless of the speed, this requires more processing power. If the speed of an object is high you should use continuos to avoid that bug.

Here’s the manual if you want to dig a little deeper into Ridigbodies https://docs.unity3d.com/2019.4/Documentation/Manual/class-Rigidbody2D.html

So maybe the problem was the speed the ball was getting up to then.

I have applied this change to limit the speed of the ball and it works: Autoplay loses the game, and ball smashing through the walls

So with that in place I might be able to switch back to discreet.

Note that I found his limit of 50 was still too fast, so I have it set to 25. I will have to test it on autoplay mode for a while to verify it doesn’t happen again at that speed.

Thanks for the help and the explanation!

Is the issue fixed?


See also:

Yes, it is solved based on my testing today, so I have marked that as the solution. I have added another solution that caps the maximum speed of the ball that may allow me to go back to using Discrete mode, but that will require further testing to verify it.

I think the problem shows up because the randomizing of the bounce was also accelerating the ball. With a lot of blocks, especially multi-hit blocks, the ball gets going extremely fast. So limiting the max speed is a Good Thing to keep the game playable. It way to make levels more difficult would be to change what the max speed can be so it can get higher on the higher levels.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms