I'm making a pong game where you can rotate the paddles.
I'm working on the computer AI atm, and i want the computer to know how to rotate to make the ball go in the desired direction.
The question is, how do you calculate the normal vector that the paddle will have to reflect the ball off of, in order to make the ball go from traveling in directionA to traveling in directionB
Calculating Reflection Normal
The question is, how do you calculate the normal vector that the paddle will have to reflect the ball off of, in order to make the ball go from traveling in directionA to traveling in directionB
If the ball is traveling in direction A, it has the velocity vector A (dx, dy). Then, the desired resulting direction is the velocity vector B (dx, dy).
You can then get theta (angular direction) with tan(dy/dx).
The paddle's normal should be the average of (-theta of A) and (theta of B ).
Normal Angle =...
= (-(theta of A) + (theta of B )) / 2
= (-tan(A.dy/A.dx)+tan(B.dy/B.dx))/2
I think
Make sure to check for cases where dx == 0, since this will result in a divide by zero!
This should work...
I' = I - 2 * dot(N, I) * N
Where I = incoming direction vector (normalised) and N = normal of the paddle (normalised)
I' = I - 2 * dot(N, I) * N
Where I = incoming direction vector (normalised) and N = normal of the paddle (normalised)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement