PDA

View Full Version : Isometric AI


mrownage
09-15-2008, 11:27 AM
Hey every one i am making an Isometric game at the moment, I have my player walking very well, I have my map all set out with the scolling screens working perfectly... my only issue are my enemies, they follow the player fine but when it comes to the sprite change it becomes very ugly, up down left and right are fine but the diaginals make the enemy freeze (only the animation not the movment)

Can anyone help me?

rrh
09-15-2008, 05:07 PM
Throw in a bunch of traces until you can narrow down what loop is making it freeze.

mrownage
09-16-2008, 12:16 PM
Iv found a solution... kinda, the script im using looks like this:

onClipEvent (enterFrame) {
ux = _root.hero._x;
uy = _root.hero._y;
ex = this._x;
ey = this._y;
if (ux<ex) {
this._x -= 3;
this.gotoAndStop(3);
} else {
if (ux>ex) {
this._x += 3;
this.gotoAndStop(4);
} else {
if (uy<ey) {
this._y -= 3;
this.gotoAndStop(2);
} else {
if (ux>ey) {
this._y += 3;
this.gotoAndStop(1);
}
}
}
}
}


What happens now is my monster will walk up, down, left, or right and never on an angle. However when I put this into action my monster walks on the X axis no worries and it even plays the animations perfectly, the Y axis on the other hand, my monster dosnt move Up or down Y and the animations being played are "walking left" and "walking right" and they flip between each other nonstop.

Im really lost I more then sure my code should be working but its not, can some one help me?

rrh
09-17-2008, 09:18 PM
Well, consider the way your if statements are arranged.


if (ux<ex) {
this._x -= 3;
this.gotoAndStop(3);
} else {
if (ux>ex) {
this._x += 3;
this.gotoAndStop(4);
} else {
//HERE
if (uy<ey) {
this._y -= 3;
this.gotoAndStop(2);
} else {
if (ux>ey) {
this._y += 3;
this.gotoAndStop(1);
}
}
}
}


Note the point where I wrote //HERE. That line will only be reached if ux==ex, and since you are moving by values of 3, it could completely skip over it.

You should either set a larger range, or use Math.abs(ux-ex) and Math.abs(uy-ey) to decide whether to move horizontally or vertically.

mrownage
09-18-2008, 09:28 PM
Sweet thanks alot its working like a dream :P Ill keep you posted if I need anymore help.

mrownage
09-21-2008, 10:18 PM
Ok now that my enemy moves how I want, Im trying to make a number of diffrent enemy types. I have a guy who jst follows you and trys to hit you with a club, but now I need a ranged attacker. So far this archer works fine I used PI to make him able to rotate and look at the player no matter where he is... making him shoot isnt so easy for me. I have looked at countles shooting tutorials but none match my need. Can anyone help me?