All pastes #367389 Raw Edit

Unnamed

public text v1 · immutable
#367389 ·published 2007-02-22 09:45 UTC
rendered paste body
					trace('hit' + i);
					var hitangle = (Math.atan2(dijx, dijy)) / Math.PI * 180;
					
					var s1 = Math.sqrt(_root.Balls[i].velocity[0] * _root.Balls[i].velocity[0] + _root.Balls[i].velocity[1] * _root.Balls[i].velocity[1]);
					var s2 = Math.sqrt(_root.Balls[j].velocity[0] * _root.Balls[j].velocity[0] + _root.Balls[j].velocity[1] * _root.Balls[j].velocity[1]);
					
					if(s1 > 0)
					{
						_root.Balls[i].velocity[0] /= s1;
						_root.Balls[i].velocity[1] /= s1;
					}
						
					if(s2 > 0)
					{
						_root.Balls[j].velocity[0] /= s2;
						_root.Balls[j].velocity[1] /= s2;
					}
						
					var dijl = Math.sqrt(dijx*dijx + dijy*dijy);
					var djil = Math.sqrt(djix*djix + djiy*djiy);
					
					if (dijl > 0)
					{
						dijx /= dijl;
						dijy /= dijl;
					}
					
					if(djil > 0)
					{
						djiy /= djil;
						djiy /= djil;
					}
					
					if(s1 > 0)
					{
						var scale = ((_root.Balls[i].velocity[0] * dijx) + (_root.Balls[i].velocity[1] * dijy)) * -2.0;
						_root.Balls[i].velocity[0] = _root.Balls[i].velocity[0] + (dijx * scale);
						_root.Balls[i].velocity[1] = _root.Balls[i].velocity[1] + (dijy * scale);
					}
					else
					{
						_root.Balls[i].velocity[0] = dijx;
						_root.Balls[i].velocity[1] = dijy;
					}
					
					if(s2 > 0)
					{
						var scale = ((_root.Balls[j].velocity[0] * djix) + (_root.Balls[j].velocity[1] * djiy)) * -2.0;
						_root.Balls[j].velocity[0] = _root.Balls[j].velocity[0] + (djix * scale);
						_root.Balls[j].velocity[1] = _root.Balls[j].velocity[1] + (djiy * scale);
					}
					else
					{
						_root.Balls[j].velocity[0] = djix;
						_root.Balls[j].velocity[1] = djiy;
					}
					
					var s3 = (s1 + s2) * 0.5;
					
					_root.Balls[i].velocity[0] *= s3;
					_root.Balls[i].velocity[1] *= s3;
					_root.Balls[j].velocity[0] *= s3;
					_root.Balls[j].velocity[1] *= s3;