The two equations you need to calculate collision impulse are:
Total momentum before = total momentum after
m1*v1i + m2*v2i = m1*v1f + m2*v2f
"i" means initial and "f" means final.
We also need another equation so we can solve for the two unknowns (v1f and v2f). Since we want perfectly elastic collisions we can use:
total kinetic energy before = total kinetic energy after
0.5*m1*v1i^2 + 0.5*m2*v2i^2 = 0.5*m1*v1f^2 + 0.5*m2*v2f^2
So with some algebra I was able to calculate it as:
v1f = (v1i*(m1-m2) + 2*v2i*m2)/(m1+m2)
v2f = (-v2i*(m1-m2) + 2*v1i*m1)/(m1+m2)
Now those velocities are in only one dimension. For 2d collisions if we only need to consider the speeds along the normal between the two objects, which is still is one dimensional.
So the steps would be:
1. calculate the normal between the two objects.
--- normalx=cos(angle from object1 to object2)
--- normaly=sin(angle from object1 to object2)
2. calculate v1i and v2i only in direction of the normal.
--- v1i = normalx*object1.velocityx+normaly*object1.velocityy
3. use the equations above to calculate v1f and v2f.
4. apply v1f and v2f back onto the object's velocties.
--- add normalx*(v1f-v1i) to object1 velocityx
--- add normaly*(v1f-v1i) to object1 velocityy
https://dl.dropboxusercontent.com/u/542 ... ounce.capx
You can also incorporate a coefficient of restitution into the impulse equation so you can anything from a "perfectly elastic collision" to an "inelastic collision".