Alright so, I got a little pong game running and everything has been going pretty smoothly apart from this 1 major flaw/glitch - the ball will suddenly start going into the paddle and start giving the player a bunch of points.
If you can help me with this it would be much appreciated, If any code is needed just ask and ill oblige.
I think you're thinking of the ball approaching the paddle from the southwest at a 45 degree angle. But in general a 90-degree turn won't do; think about the ball approaching the paddle from the left, horizontally. Instead of bouncing back, your ball will move upward.
Turning by 180 won't, in general, give the physically correct bounce angle, but at least it'll move back away from the paddle. So it's a nice simple okay solution.
The physically perfect solution has to use the ball's DIRECTION in computing the turn.
As I understand this going back 5 works in 'easy' mode where the most the ball has moved 5 steps. But if the ball moved 10 steps the ball may have penetrated the paddle by more than 5 steps.
Also while turning 180 isn't generally what real balls do.Itt guarantees you will back out the way you came in. But if you take 5 steps to back out at another angle you might still end up inside the paddle.
When I said 180 degrees, I meant 90. As bh has said, the rotaton is conditional. If the ball is facing 45 or -45 degrees, use 90 degrees counter clockwise. Is the ball is facing 135 or -135 degrees, use 90 degrees clockwise.
For the 10 steps thing, I have 2 solutions:
1: Do some crazy complicated recasting stuff to see if the ball will go through the paddle.
One easy solution for the bounce angle is to multiply the current direction by -1. With respect the ball getting "stuck" inside the paddle, this can be addressed by giving the ball a "cool down" before it's allowed to bounce again (a wait 0.25 seconds is enough).
Fix the immediate problem where the ball is stuck in the paddle but produce a clearly incorrect bounce?
Fix the stuck ball AND produce a classic version of Pong (with vertical paddles)
Produce a generic Pong where paddles can be any orientation (and shape?). Requires a deep dive into bouncing which may or may not be appropriate for this project.