08 - Collision Response/script.js
//calculates the balls new velocity vectors after the collision

calculates the balls new velocity vectors after the collision
calculates the balls new velocity vectors after the collision
function coll_res_bb(b1, b2){
    let normal = b1.pos.subtr(b2.pos).unit();
    let relVel = b1.vel.subtr(b2.vel);
    let sepVel = Vector.dot(relVel, normal);
    let new_sepVel = -sepVel;
    let sepVelVec = normal.mult(new_sepVel);
    b1.vel = b1.vel.add(sepVelVec);
    b2.vel = b2.vel.add(sepVelVec.mult(-1));
}
function coll_res_bb ( b1 , b2 ) { let normal = b1 . pos . subtr ( b2 . pos ) . unit ( ) ; let relVel = b1 . vel . subtr ( b2 . vel ) ; let sepVel = Vector . dot ( relVel , normal ) ; let new_sepVel = - sepVel ; let sepVelVec = normal . mult ( new_sepVel ) ; b1 . vel = b1 . vel . add ( sepVelVec ) ; b2 . vel = b2 . vel . add ( sepVelVec . mult ( - 1 ) ) ; }
calculates the balls new velocity vectors after the collision
calculates the balls new velocity vectors after the collision
//collision normal vector
 //relative velocity vector
 //separating velocity - relVel projected onto the collision normal vector
 //the projection value after the collision (multiplied by -1)
 //collision normal vector with the magnitude of the new_sepVel
 //adding the separating velocity vector to the original vel. vector
 //adding its opposite to the other balls original vel. vector
