Circle Circle Frame Independant Collision Reaction

Trying to do circle circle collisions via math which I’m really having trouble with. One circle (player) just moves from keyboard. The ball reacts to the player. All the code shown is in my players class and I passed in a reference to the ball.

On my enterframe I have:


var xmov1 = xSpeed;
            var ymov1 = ySpeed;
            var xmov2 = ballRef.xSpeed;
            var ymov2 = ballRef.ySpeed;
            
            var xl1 = this.x;
            var yl1 = this.y;
            var xl2 = ballRef.x;
            var yl2 = ballRef.y;
            
            var R =  radius+ ballRef.radius;
            var a = -2*xmov1*xmov2+xmov1*xmov1+xmov2*xmov2;
            var b = -2*xl1*xmov2-2*xl2*xmov1+2*xl1*xmov1+2*xl2*xmov2;
            var c = -2*xl1*xl2+xl1*xl1+xl2*xl2;
            var d = -2*ymov1*ymov2+ymov1*ymov1+ymov2*ymov2;
            var e = -2*yl1*ymov2-2*yl2*ymov1+2*yl1*ymov1+2*yl2*ymov2;
            var f = -2*yl1*yl2+yl1*yl1+yl2*yl2;
            var g = a+d;
            var h = b+e;
            var k = c+f-R*R;
            
            var sqRoot = Math.sqrt(h*h-4*g*k);
            var t1 = (-h+sqRoot)/(2*g);
            var t2 = (-h-sqRoot)/(2*g);
            if (t1>0 && t1<=1) {
                whatTime = t1;
                ballsCollided = true;
             }
             if (t2>0 && t2<=1) {
                if (whatTime == null || t2<t1) {
                  whatTime = t2;
                  ballsCollided = true;
                }
             }
             if (ballsCollided) {
                collisions(this, ballRef, this.x, this.y, ballRef.x, ballRef.y, whatTime);
             }

The collisions funtion looks likes this:


function collisions(b1, b2, x1, y1, x2, y2, time) {
            var mass1 = b1.mass;
            var mass2 = b2.mass;
            
            var xVel1 = b1.xSpeed;
            var yVel1 = b1.ySpeed;
            
            var xVel2 = b2.xSpeed;
            var yVel2 = b2.ySpeed;
            
            
            var run = (x1-x2);
            var rise = (y1-y2);
            var Theta = Math.atan2(rise, run);
            var cosTheta = Math.cos(Theta);
            var sinTheta = Math.sin(Theta);
            
            var xVel1prime = xVel1*cosTheta+yVel1*sinTheta;
            var xVel2prime = xVel2*cosTheta+yVel2*sinTheta;

            var yVel1prime = yVel1*cosTheta-xVel1*sinTheta;
            var yVel2prime = yVel2*cosTheta-xVel2*sinTheta;
            
            var P = (mass1*xVel1prime+mass2*xVel2prime);
            var V = (xVel1prime-xVel2prime);
            var v2f = (P+mass1*V)/(mass1+mass2);
            var v1f = v2f-xVel1prime+xVel2prime;
            xVel1prime = v1f;
            xVel2prime = v2f;
            
            xVel1 = xVel1prime*cosTheta-yVel1prime*sinTheta*time;
            xVel2 = xVel2prime*cosTheta-yVel2prime*sinTheta*time;
            yVel1 = yVel1prime*cosTheta+xVel1prime*sinTheta*time;
            yVel2 = yVel2prime*cosTheta+xVel2prime*sinTheta*time;
            
            b2.xSpeed = xVel2;
            b2.ySpeed = yVel2;
        }

Perhaps I’ll go with a box2d equivalent instead of trying out my own physics shenanigans. If you wanna link me to a box2d tut for balls and keyboard movement that would be ok too, but if I get no responses I use my non Easter celebrating friend google.
Thanks