This is for action-script 2.0.

Well, if you've gone though my moving character tutorials, or if you already know how to make moving characters...you may be wondering "How can I make an AI enemy? A monster if you will.". As always, I'm here to help!

First things first, make sure your character movie-clip (as I am assuming it is already made) has the instance name "character".

Now, lets make the movie-clip for the AI (give it the instance name "AI1" (It is set up very similarly to your character movie-clip). In fact, set it up EXACTLY as you did your character, except use this script in the "AI1" movie-clip. And you MUST have everything in the AI1 movie-clip placed at 0,0.


onClipEvent(enterFrame){

var AI_speed = 1.5; //the higher this number the faster the AI moves
var reaction_distance = 500; //this higher this number, the farther the AI can "see" your character from.

var AI_width = this._xscale;
var AI_highth = this._yscale;

if(this._x < _parent.character._x){ var view_direction = "right"; var x_dif = _parent.character._x - this._x; var y_dif = _parent.character._y - this._y; } else { var view_direction = "left"; var x_dif = this._x - _parent.character._x; var y_dif = this._y - _parent.character._y; } if(y_dif <= reaction_distance){ if(view_direction == "left"){ gotoAndStop("jumping"); } else { gotoAndStop("crouching"); } } if(x_dif <= reaction_distance){ if(view_direction == "left"){ this._xscale = -100; this._x -= 2; if(_global.jumping != "yes"){ gotoAndStop("walking"); } } else { this._xscale = 100; this._x += 2; if(_global.jumping != "yes"){ gotoAndStop("walking"); } } } }//end on Clip Event

Be Sociable, Share!