PDA

View Full Version : Artificial Intelligence



emilio7
September 13th, 2008, 05:00 PM
Hi everyone, it`s me again. :}
I got a new problem, working with AI, the thing is this: am making a MK game, and i want that the enemy attacks my player, so, i add those codes to the player movieclip:


onClipEvent (enterFrame) {
distance = 300;
rx = _root.char._x;
ry = _root.char._y;
tx = _root.enemy._x;
ty = _root.enemy._y;
if (Math.sqrt((rx-tx)*(rx-tx)+(ry-ty)*(ry-ty))<distance) {
this._parent.enemy.gotoAndPlay("2");
}
}


enemy= the movieclip of the enemy.
char= movieclip of the player.

In frame 2 of the enemy clip, i got the action Stop, and i movieclip with one frame, that shows the enemy`s punch.
With that, i make that when the player come closer to the enemy, the enemy attacks him, the problem that i got, is that i made a movieclip called "block" the first frame of this, is in blank, and got the "stop" action, the second frame got the "block!" text, and the third is in blank, and has this code:

this._parent.enemy.gotoAndStop("1");


In first frame of the enemy movieclip, theres the enemy stand, so that won`t hurt my player, this works fine, but, when the player aproches to the enemy, this GotoandPlay the second frame, with the punch, and when a press the button that activates the "block" movieclip, this didnt work! I dont understand why, because the movieclip of "block" appears, but the enemy keep (like frozen) doing the punch, what i did wrong?, or, is other way to do this??

Thank you.:}

fugnug
September 13th, 2008, 09:45 PM
You may want to add a boolean to your object to be like this.animation=true; at the beginning of any animation and in the last frame put this.animation=false;

and modify anything that would override the animation like this:
if (Math.sqrt((rx-tx)*(rx-tx)+(ry-ty)*(ry-ty))<distance)
to this:
if (Math.sqrt((rx-tx)*(rx-tx)+(ry-ty)*(ry-ty))<distance && !enemy.animation)