somebody621
Member
|
SAT = the separating axis theorem. It's a good collision algorithm. I understand the theory and know how to do it, but still have some bugs. Edit: var dist:Number = 800;
var centerX:Number = Stage.width/2;
var centerY:Number = Stage.height/2;
var pi = Math.PI;
var wave = new Object();
var fl:Number = 250;
wave.radius = 50;
wave.interval = 25;
wave.angle = 15.5;
_root.lineStyle( 1, 0x0000ff, 100 );
for(y = -centerX; y<Stage.height; y+= wave.interval){
var loop:Number = y/wave.interval
var d1:String = "Object1_" + loop;
wave[d1] = new Object();
var d2:String = "Object2_" + loop;
wave[d2] = new Object();
var o1:Object = wave[d1];
var o2:Object = wave[d2];
var a:Number = y * wave.angle;
var radians:Number = a * pi/180;
o1.z = Math.sin(radians)*wave.radius;
o1.x = Math.cos(radians)*wave.radius;
o1.y = y - centerY + 25;
o2.x = o1.x * -1;
o2.z = o1.z * -1;
o2.y = o1.y;
var n1:String = "b1_" + loop;
var n2:String = "b2_" + loop;
_root.attachMovie("b", n1, loop + 1000);
_root.attachMovie("b", n2, loop);
}
function onEnterFrame():Void {
clear();
_root.lineStyle( 1, 0x0000ff, 100 );
for (var i:Number = 0; i<loop; i++) {
var n1:String = "b1_" + i;
var n2:String = "b2_" + i;
var b1:MovieClip = _root[n1];
var b2:MovieClip = _root[n2];
var ball:Object = wave["Object1_"+i];
var ball2:Object = wave["Object2_"+i];
var angleY:Number = (centerX)*.0005;
var cosY:Number = Math.cos(angleY);
var sinY:Number = Math.sin(angleY);
var x1:Number = ball.x*cosY-ball.z*sinY;
var z1:Number = ball.z*cosY+ball.x*sinY;
var x2:Number = ball2.x*cosY-ball2.z*sinY;
var z2:Number = ball2.z*cosY+ball2.x*sinY;
ball.x = x1;
ball.z = z1;
ball2.x = x2;
ball2.z = z2;
var scale:Number = fl/(fl+ball.z);
b1._xscale = b1._yscale=scale*100;
b1._x = centerX+ball.x*scale;
b1._y = centerY+ball.y*scale;
var j:Number = -ball.z;
while(_root.getInstanceAtDepth(j) != undefined){
j--;
}
b1.swapDepths(j);
var scale2:Number = fl/(fl+ball2.z);
b2._xscale = b2._yscale=scale2*100;
b2._x = centerX+ball2.x*scale2;
b2._y = centerY+ball2.y*scale2;
var k:Number = -ball2.z;
while(_root.getInstanceAtDepth(k) != undefined){
k--;
}
b2.swapDepths(k);
moveTo(b1._x, b1._y);
lineTo(b2._x, b2._y);
}
}
< Message edited by somebody621 -- 9/5/2006 19:55:43 >
|