Hi @HypedOnCoffee,
Welcome to our community!
The underlying problem is this: We manipulate the transform.position
via code and override the calculated values of the physics engine. Since Unity’s physics simulation is highly optimised, it is likely that the position of the ball does not match the position of the collider anymore.
My solution is more performant than Rob’s because it removes the ball from the physics simulation as long as it is glued to the paddle. Each object in the physics simulation requires Unity to calculate things.
Rob solves the problem of the optimised collision detection, which can make colliders miss other collider in certain cases. His solution could also solve the current problem (see above) because a different mode could make the physics simulation check the position of the game object more often. This is, of course, less performant than removing the ball from the simulation.
If you ask another programmer, it might be that they will come up with a third solution. That’s not uncommon because, in many cases, there are multiple ways to get things done. Don’t get confused by different solutions for the same problem. Try to understand the ideas and opt for the one which you feel solves your problem best. Maybe you will even come up with your own solution.
Did this help?
See also: