PDA

View Full Version : running away?



rmthegreat88
October 28th, 2004, 04:45 PM
how do you make an enemy run away when you (main charachter) come into a certain distance.

the script i have so far is

onClipEvent (enterFrame) {
if (this._x<_root.MC._x && this._x > 0) {
_x -= 5;
}
if (this._x>_root.MC._x && this._x < 550) {
_x += 5;
}
if (this._y<_root.MC._y && this._y > 0) {
_y-= 5;
}
if (this._y>_root.MC._y && this._y < 400) {
_y += 5;
}
}

however, all the running things do is hide in a corner.

i want them to move around randomly until you come within a certian radius, then they move away from you with increasing speed.

thanks!

Dr Warm
October 28th, 2004, 07:00 PM
want them to move around randomly until you come within a certian radius do u know the distance formula?
distX = this._x - _root.MC._x;
distY = this._y - _root.MC._y;
//need to square each of them to get a positive result
totalDist = (distX*distX)+(distY*distY);

and then u would do:
//20 is a number you decide on, you probably want it bigger
if(totalDist > 20){
//put your moving away code
}

i'm not really sure how you would get him to stay out of a corner though, unless you want just to loop him around to the other side

i assume you've already read this two tutes, here (http://www.kirupaforum.com/forums/showthread.php?t=16649) and here (http://www.kirupaforum.com/forums/showthread.php?t=72863).....