Be a Supporter!

_xscale changing for unknown reason

  • 254 Views
  • 2 Replies
New Topic Respond to this Topic
IzaacBarratt
IzaacBarratt
  • Member since: Oct. 19, 2007
  • Offline.
Forum Stats
Member
Level 14
Animator
_xscale changing for unknown reason May. 31st, 2012 @ 06:14 AM Reply

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

MintPaw
MintPaw
  • Member since: Jun. 11, 2006
  • Offline.
Forum Stats
Member
Level 10
Programmer
Response to _xscale changing for unknown reason Jun. 6th, 2012 @ 11:28 AM Reply

What is the variable "scale" ?

The easiest way I've found to flip an object is _xscale *= -1


If ya have something to say, PM me. I have a lot of time to spare.
Also never PM egg82.

BBS Signature
CaiWengi
CaiWengi
  • Member since: Sep. 17, 2004
  • Offline.
Forum Stats
Member
Level 07
Programmer
Response to _xscale changing for unknown reason Jun. 6th, 2012 @ 08:10 PM Reply

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.


BBS Signature