Ultimate Gear War
Join the alien war, prepare your gear and protect your base at all cost!
4.17 / 5.00 16,219 ViewsI have an enemy AI that follows my "player" but for some reason whenever it's on the left side of my player it turns to the right when it touches him :/
if (Math.sqrt((sx-tx)*(sx-tx)+(sy-ty)*(sy-ty))<distance) {
if (tx<sx+50) {
this.gotoAndStop(2);
this._x+=5;
this._xscale = scale;
}
if (tx>sx-200) {
this.gotoAndStop(2);
this._xscale = -scale;
this._x-=5;
}
}
I tried putting the second part at 200 pixel difference to see if he turned because his axis was slightly over the "players" but that didn't seem to work. every time he gets within the designated space he flips from -scale to scale. but he doesn't change from scale to -scale
I probably haven't explain very well to be honest, but I would appreciate any help/suggestions
What is the variable "scale" ?
The easiest way I've found to flip an object is _xscale *= -1
At 5/31/12 06:14 AM, IzaacBarratt wrote: I have an enemy AI that follows my "player" but for some reason whenever it's on the left side of my player it turns to the right when it touches him :/
if (Math.sqrt((sx-tx)*(sx-tx)+(sy-ty)*(sy-ty))<distance) {
if (tx<sx+50) {
this.gotoAndStop(2);
this._x+=5;
this._xscale = scale;
}
if (tx>sx-200) {
this.gotoAndStop(2);
this._xscale = -scale;
this._x-=5;
}
}
I tried putting the second part at 200 pixel difference to see if he turned because his axis was slightly over the "players" but that didn't seem to work. every time he gets within the designated space he flips from -scale to scale. but he doesn't change from scale to -scale
I probably haven't explain very well to be honest, but I would appreciate any help/suggestions
Can't you use 100 and -100 instead of scale and -scale whatever they mean. Also we have no idea what tx and sx are in your code and they are pretty vital things to this problem.