I'm creating a pong game with C++ for a University project. I have this snippet of code that check to see if my ball sprite has hit the boundary of my screen. When it does, it will multiply my ball_direction.y value (for a vector) by -1 to produce a bounce. However, most of the time this works, but sometimes the ball will simply go through and off the screen without bouncing, and sometimes it will get stuck on the edge and bounce back and forth before flying off the screen again.
I'm really not sure why this works, and I haven't found a solution. If you need to see other areas of my code, please ask, I'm still pretty new to this.