10 - Adding the Walls/script.js
//collision response between ball and wall

collision response between ball and wall
collision response between ball and wall
function coll_res_bw(b1, w1){
    let normal = b1.pos.subtr(closestPointBW(b1, w1)).unit();
    let sepVel = Vector.dot(b1.vel, normal);
    let new_sepVel = -sepVel * b1.elasticity;
    let vsep_diff = sepVel - new_sepVel;
    b1.vel = b1.vel.add(normal.mult(-vsep_diff));
}
function coll_res_bw ( b1 , w1 ) { let normal = b1 . pos . subtr ( closestPointBW ( b1 , w1 ) ) . unit ( ) ; let sepVel = Vector . dot ( b1 . vel , normal ) ; let new_sepVel = - sepVel * b1 . elasticity ; let vsep_diff = sepVel - new_sepVel ; b1 . vel = b1 . vel . add ( normal . mult ( - vsep_diff ) ) ; }
collision response between ball and wall
collision response between ball and wall