Better way to handle collisions?

Hello everyone. I’m an oldschool gamer so I’m familiar with the classics like Arkanoid and Revenge of Doh. In those games, there were no simulations and the ball was bouncing off almost always like you expect it would. When unity handles the simulations I’m guessing the ball sometimes hits a corner or it hits two blocks at once and it bounces off in weird angles. Is there a better way to code these bounces or some setting in physics settings that would prevent these issues?

Hi marul,

Welcome to our community! :slight_smile:

When unity handles the simulations I’m guessing the ball sometimes hits a corner or it hits two blocks at once and it bounces off in weird angles.

Did you see that behaviour with your own eyes? If not, I would recommend not to write any solutions for potentially non-existent problems.

If you get the problem in your game, you’ll have to analyse it. Maybe the collider shapes were not set up correctly. Maybe setting the collision detection of the ball’s Rigidbody2D component to “Continuous” solves the problem. Maybe one could increase a few iteration values in the Physics2D Settings. That’s impossible to tell without experiencing the problem yourself.

Without knowing why a problem occurs, it is almost impossible to write a solution for that specific problem. You could certainly write a solution for 1000s of different edge cases and work around Unity’s simulation but that’ll probably take so much time that using a different game engine or writing your own game engine would have been a better solution.

I hope I understood your question correctly. If not, please let me know. :slight_smile:


See also:

Thanks for the response. Yes, I experienced this myself and I’m not saying the calculations are incorrect. What bothers me is the angle of the ball after the collision; I don’t want to achieve a simulation solution, rather a predictable bounce-off effect. You would probably understand what I’m talking about if you played some games like I mentioned in the genre. Changing the setting to “continuous” didn’t make much difference. From what I understand, I have to write a script to calculate the bounce off myself rather than let unity physics engine handle it.

I’ve found an example for 3d here: https://unity3d.college/2017/07/03/using-vector3-reflect-to-cheat-ball-bouncing-physics-in-unity/

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

Privacy & Terms