- Flash Tutorial 1
- Flash Tutorial 2
- Flash Tutorial 3: Event Detection
- Flash Tutorial 4: Fun with the Cursor!
- Flash Tutorial 5: A Moving Character Type 1
- Flash Tutorial 6: A Moving Character Type 2
- Flash Tutorial 7: AI Enemies Type 1
- Flash Tutorial 8: AI Enemies Type 2
- Flash Animation/Effects Tutorial 1: Motion Tweens
- Flash Animation/Effects Tutorial 2: Shape Tweens
Flash Tutorial 7: AI Enemies Type 1
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.
Code:
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
And your done \^_\^ (that was easy hu?)
Printer-friendly version- Login or register to post comments
- Send to friend
- PDF version