Search code examples
mathvectorgame-physics

Calculate angle Pinball


Right now I am coding a Pinball clone in ActionScript (actually in this case the language doesn't matter). I have the following problem: I have two paddles and a ball moving with a certain speed (represented as a velocity vector). I can't figure out how to calculate the new velocity vector of the ball after hitting the paddle. All my calculations are going terribly wrong.

What I have: Current angle of the paddle (in radians), the velocity vector of my ball and the current angle (in radians) of that vector where 1,5708 (90 degrees) is straight down (e.g. velocity vector with x = 0 and y = 5).

Does anyone have an idea how to approach this. The programming language doesn't matter here - pseudo code is also fine.


Solution

  • You need to mirror the velocity vector (vx,vy) on the line with direction

    (c,s) = ( cos(anglePaddle), sin(anglePaddle))
    

    so that the component orthogonal to it gets reverted and the component parallel to it remains the same. The orthogonal component is

    (-s,c)*(-s*vx+c*vy)
    

    so that the reflected vector becomes

    (vx,vy) - 2*(-s,c)*(-s*vx+c*vy) = ( c2*vx + s2*vy, s2*vx - c2*vy )
    

    where double angle trigonometric identities where used to simplify using

     (c2,s2) = ( cos(2*anglePaddle), sin(2*anglePaddle)).