The day came that I wanted to refresh my knowledge of physics in Unity. However, I ran into a problem.
The scenario is as follows. Classic pong, two paddles and a ball bouncing between them. Serve the ball thrown in a random direction, everything works perfectly as intended.
However, I started looking for loopholes in this scenario. I modified the ball’s serve to move perfectly horizontally, bouncing between the stationary paddles from left to right. Another point as expected.
However, if I move the paddle up and down, why doesn’t the ball change its bounce angle? Of course, I can, for example, write the sum of the ball velocity vector and the paddle velocity vector myself, which will simulate a bounce at an angle. Of course, some of this speed must be knocked out based on some elementary school formula.
My question, however, is whether the default Unity physics is able to do such things on its own? Here, maybe I don’t know something, I don’t understand, maybe I need to tweak some parameter? Thanks in advance if you can point me in the right direction. I’m trying to expand my understanding of the engine itself.
I will clarify the question to be sure. Is Unity physics (standalone) able to calculate the angle of reflection for two moving objects after a collision.
I would like to emphasize that the above text is not a question about how to make pong.
I decided to answer myself, maybe someone will have similar thoughts.
I compared my project with others from tutorials available on the Internet. The scenario I described below was repeated on each. The problem was only masked by the random ball serve (angle).
The problem was related to the material used on the ball, i.e. the bounciness was set to 1, but the friction was set to 0. As a result, the ball was not pulled up/down with the paddle on the bounce.
The default physics worked fine, I passed the material parameters of the ball wrong. However, the addition of friction caused the ball to stop after some time. And that means that I simply used an unrealistic physical scenario.
In short yes, this is possible through the parameter of friction in the physical material. A value of 0, however, does not provide friction to bounce the ball at an angle using the default physics. Here I mean perfectly horizontal or vertical movement of the ball. Angled strikes always work.
A separate topic is the infinitely moving ball. Velocity must be kept constant by other way than getting rid of the friction on the physical material.