Hey All,
I'm having some issues with my collision response for a breakout style game. Currently my circle (ball) to rectangle (bricks/paddle) detection works fine, however the response is acting odd. Engine used is SFML.
I searched up the vector reflection equation, however I think I may be implementing it wrong (particularly the normal).
CODE
r=u-2(u.n)n
Where n is the normal of the plane and u is the incident vector.
Here is my code implementation:
CODE
ballVel = ballVel - 2 * ((paddlePos.normalise() * ballVel) + (paddlePos.normalise() * ballVel)) * paddlePos.normalise;
I believe I may be caclulating the normal wrong, however I havn't been able to find any defnitive formulas.
Currently upon a collision with the paddle, the ball will bounce in an upwards direction, continuing this until it is moving perfectly up and down. Playing around with the equation etc just causes the ball to bounce back in the direction it came, although at a slightly different angle. Any ideas on how to implement correct circle-rectangle collision response?
Sorry if I havn't posted enough code etc, first time asking on a forum for programming help.
Thanks, Jmatt.