At 3/18/09 09:56 PM, Frankmank wrote:
http://spamtheweb.com/ul/upload/180309/8 2217_officefight.php
SPACEBAR TO ATTACK
Right now when I enemy AI spots the player he goes after him, but it's REALLY jumpy as you can see.
Here's the code for it:
onClipEvent(enterFrame){
d = 1.2;
if (_root.attack == true) {
this.legs.play();
if(this._x<_root.player._x){
this._x+=d;
this.gotoAndStop(2);
}else if(this._x>_root.player._x){
this._x-=d;
this.gotoAndStop(3);
}
if(this._y<_root.player._y){
this._y+=d;
}else if(this._y>_root.player._y){
this._y-=d;
}
}
}
Wondering how I could make it smoother? thanks.
Ur problem is that when you move the enemy, you move it by a weird number. Here, ill give you an example:
_root.player._x = 10
this._x = 9
With ur code, the enemy's x will increase by 1.2, leaving this:
_root.player._x = 10
this._x = 10.2
Now, the enemy's x will go down by 1.2, going back to _root.player._x = 10 and this._x = 9
This will repeat itself over and over again, producing the "jumping" you see.
I would suggest changing d so that it equals one, and stick with integers in both the player's x and y co-ordinates and the Ai's x and y co-ordinates. Hope this helps