Flash 8 - AS2
I have 2 points moving around on the screen, p1 and p2, every step I want the distance between these points to be 100 .
I know that the distance between the points is the square root of the distance x squared and distance y squared but how would I change those points to make them 100 apart.
I have had a go but it failed :*(
Here is my attempt:
line.onEnterFrame = function() {
dx = this.p2._x-this.p1._x;
dy = this.p2._y-this.p1._y;
dist = Math.sqrt(dx*dx+dy*dy);
if (dist != 100) {
dist -= 100;
dist /= 2;
angle = Math.atan2(dy, dx)*180/Math.PI;
x = Math.cos(angle*Math.PI/180)*dist;
y = Math.sin(angle*Math.PI/180)*dist*-1;
this.p1._x += x;
this.p1._y += y;
this.p2._x -= x;
this.p2._y -= y;
}
this.clear();
this.lineStyle(10, 0x000000);
this.moveTo(this.p1._x, this.p1._y);
this.lineTo(this.p2._x, this.p2._y);
};
Thanks for any help.