Mexxa:
Here's the basic idea of the script you're after... I've done one like this before to handle the homing missiles and 'smart' badguys in AB:Spermicide.
You need a function that tracks a waypoint, or a target. This is useful not only for having a badguy follow you, but also for having one move along a path, like a racetrack or something. What it does is check to see if it is off center from it's destination, and then turns towards it if it is. Here's a little snippet of the actual code I used:
function getMovement(){
if (Math.abs(targetTheta - _rotation) < 10 || Math.abs(targetTheta - _rotation) > 350){
_rotation = targetTheta;
turning = 0;
}
if (_rotation < targetTheta){
if(turning < turnSpeed_p) turning ++;
} else if (_rotation > targetTheta){
if(turning > -turnSpeed_p) turning --;
}
if(this.hitTest(targ.x, targ.y)){
getWayPoint();
}
pushVector(0, accel_p);
_rotation += turning;
}
in this example, turnSpeed_p was a property variable that determines how fast the clip turns. 'pushVector(0, accel_p)' was a function i wrote to add acceleration to the character based on the direction he was facing. You can remove that line and use your own script to handle acceleration. 'targetTheta' is a variable figured by another function:
function getPosition(){
if(Math.abs(_y - _parent.ship._y) < 200 && Math.abs(_x - _parent.ship._x) < 200){
targetVectorX = _parent.ship._x - _x;
targetVectorY = _y - _parent.ship._y;
} else {
targetVectorX = targ.x - _x;
targetVectorY = _y - targ.y;
}
hypVector = Math.sqrt(targetVectorX * targetVectorX + targetVectorY * targetVectorY);
targetThetaX = Math.asin(targetVectorX/hypVector)/RAD;
targetThetaY = Math.acos(targetVectorY/hypVector)/RAD;
if(targetVectorY < 0) targetTheta = 180 - targetThetaX;
else targetTheta = targetThetaX;
}
'targ' is an object that represents the target object. The reason i used x instead of _x is because it wasn't always a movie clip (sometimes, i used a custom waypoint object, with x and y properties. you can change them to _x and _y to work with an MC tho). RAD was just a constant i defined to convert from radians to degrees.
These functions just handle rotation, you'll need to add another to make the clip thrust forward, althought that's pretty simple, once you have the proper rotation. If you want the clip to wait a few seconds, start a counter variable going, and don't start running these functions until the counter hits a certain number.
If you need any more help with this script, or actually want working answers to other problems, AIM me at AngryBinary, or email angryBinary@hotmail.com
1010011010