Here's what you do to determine what angle they bounce off at. Just for the record, it's old code, and I had to change some stuff without testing for it to work the way you want it to, so you might have to tweak some things. Also, it assumes the object you're colliding with is completely stationary, but all you have to do is do it to both one, using the other as reference. As for determining bounce speed, I'd imagine there's something easy enough that combines speed with mass, adds them together, and determines how much speed each one goes away with.
"YOUR VARIABLE HERE" refers to some number that is determined by the part of your code that tells this part of the code how fast to bounce each object off.
It's not in this code, but remember at the end that v1a+v1b>v2a+v2b. This means that the total added velocities at the beginning are greater than those at the end, because almost all collisions lose some energy to heat and whatnot. That should be a start for you.
More stuff about rebound velocity: If it were me, I'd have a sort of "point system" in place, where an object gets x points for speed, and y points for mass, and when they collide, you add their points, and divide an individual's points by the whole, and using that as 'YOUR CONSTANT HERE', effectively dividing the energy between the two objects.
"YOUR VARIABLE HERE" refers to some number that is determined by the part of your code that tells this part of the code how fast to bounce each object off.
It's not in this code, but remember at the end that v1a+v1b>v2a+v2b. This means that the total added velocities at the beginning are greater than those at the end, because almost all collisions lose some energy to heat and whatnot. That should be a start for you.
'vx/vy are the velocity Local velocityAngle:Double=ATan2(vy,vx) Local normal:double=atan2(y1-y2,x1-x2) Local originalVelocity:Double=Sqr(vx*vx+vy*vy) velocityAngle=normal+(normal-(velocityAngle-360)) vx=Cos(velocityAngle)*originalVelocity*(YOUR VARIABLE HERE) vy=Sin(velocityAngle)*originalVelocity*(YOUR VARIABLE HERE)
More stuff about rebound velocity: If it were me, I'd have a sort of "point system" in place, where an object gets x points for speed, and y points for mass, and when they collide, you add their points, and divide an individual's points by the whole, and using that as 'YOUR CONSTANT HERE', effectively dividing the energy between the two objects.