AI for enemies (OSD – SC)

Here is a nifty code for your enemies, it’s pretty basic but you judge for yourself… don’t mind the Modulo symbol, you can change tht to add or multiply…

If you know your maths this will be a click in the head, you’ll figure out what it will exactly do, but if you ever need help you can always email :P (sway-emo@hotmail.com), but nuff said, her’s the code:

onClipEvent (enterFrame) {
 aX = _root.a._x;
 aY = _root.a._y;
 findX = (aX-_x)/(aX%aY-10);
 //change to findX = (aX-_x)/(aX%aY/2) for teleporting or simpler findX = (aX-_x)/(aX%aY-10)
 findY = (aY-_y)/(aY%aX+10);
 setProperty(”", _x, _x+findX);
 setProperty(”", _y, _y+findY);
 if (_x>aX-10) {
  _xscale = -100;
 }
 else if (_x<aX+10) {
  _xscale = 100;
 }
 if (this.mHit(”Y”, _root.a/2)) {
  gotoAndStop(1);
 } else {
  gotoAndStop(2);
 }
}
onClipEvent (enterFrame) {
 this.swapDepths(this._y);
}

Download link is

HERE

And optionally you can add this to your timeline:

MovieClip.prototype.mHit = function(w, ww) {
 //what with what
 switch (w) {
 case “:legs” :
  if (this.hitTest(ww._x, ww._y+(ww._height-ww._height/2), true)) {
   return true;
  } else {
   return false;
  }
  break;
 case “Y” :
  if (this.hitTest(ww._x, ww._y+9.75, true)) {
   return true;
  } else {
   return false;
  }
  break;
 case “X” :
  if (this.hitTest(ww._x, ww._y, true)) {
   return true;
  } else {
   return false;
  }
  break;
 case “:hands” :
  if (this.hitTest(ww._x+8, ww._y+9.75, true)) {
   return true;
  } else {
   return false;
  }
  break;
 }
};

 

Leave a Reply