
This is the formula I found:
r = v - [2 (n · v) n]
This is how i applied
//Calculating normal
nx = 350 - SmileyReds[i].xpos ;
ny = 350 - SmileyReds[i].ypos ;
//new calc
v_newx = SmileyReds[i].xspeed - (2 *( nx * SmileyReds[i].xspeed + ny * SmileyReds[i].yspeed ) ) * nx;
v_newy = SmileyReds[i].yspeed - (2 *( nx * SmileyReds[i].xspeed + ny * SmileyReds[i].yspeed ) ) * ny;
SmileyReds[i].xspeed = v_newx;
SmileyReds[i].yspeed = v_newy;
But instead of bouncing, the balls disappear when they hit the border:
Full src and preview http://jsfiddle.net/gj4Q7/4/
Thanks for your time, any advice is welcome!
source
share