PDA

View Full Version : Dynamic AS curve....?


bobllama
07-13-2005, 03:37 PM
Hi... posted a question a few days ago in the AS section but didn't really get an answer, hopefully you guys can help.

Here's the situation:

I'm trying to create a little MC that "shoots" "missles" that "lock-on" to the Mouse(x,y) when they are generated and head towards it but not in a straight line. They curve towards the endpoint by a random amount.

Let me clarify:

1) "Missle" is generated, Mouse(x,y) are set as destination points for said missle.
2) "Missle" heads towards endpoint but not in a straight line, rather it arcs. The extent of the arc should ideally be random (whether it deviates a lot or a little from the most direct path I mean, and especially whether it is above or below the "optimal" direct path).

I've got a working prototype using the drawing API, but not arcing, only going straight towards the endpoint. Since I'm really, really bad at trigonometry and related things (was an english major in school), I thought I should probably consult some people who are better at this than myself.

Here's my code:
this.createEmptyMovieClip("curveHolder", 1);
this.createEmptyMovieClip("mover", 2);
endX = _xmouse;
endY = _ymouse;
curveHolder._x = squarey._x;
curveHolder._y = squarey._y;
curveHolder.onEnterFrame = function() {
with (curveHolder) {
lineStyle(0, 0x000000, 100);
lineTo(squarey._x-curveHolder._x, squarey._y-curveHolder._y);
}
};
mover.onEnterFrame = function() {
squarey._x += (endX-squarey._x)/15;
squarey._y += (endY-squarey._y)/15;
};

In case you're wondering the 15 is used to slow down the amount of time it takes "squarey" (the "missle") to reach the endpoint (at 24fps).

Any help would be very much appreciated.Even if I have to rewrite my code from scratch, any help, well, helps.