I'm trying to make a defense type game and it's primitive at the moment.
The enemy has been coded to move towards the gun central, but if you watch in the flash below, he shakes around before settling.
Check out the flash here
I placed the _x and _y values so I could make sense of it.
The enemy has the following code placed on it:
onClipEvent (load) {
walkSpeed = 1.01;
Attacking = false;
}
onClipEvent (enterFrame) {
//variables
_root.boomerx = _x;
_root.boomery = _y;
_root.gunx = _root.MachineGun._x;
_root.guny = _root.MachineGun._y;
//attacking code
if (this.hitTest(_root.blockOfAttack)) {
Attacking = true;
//this.gotoAndStop("Attacking");
}
if (Attacking == true) {
this.gotoAndStop("Attacking");
}
}
onClipEvent (enterFrame) {
///movement code
if (!Attacking) {
if (_x>_root.MachineGun._x) {
this._x -= walkSpeed;
} else if (_x<_root.MachineGun._x) {
this._x += walkSpeed;
}
if (_y>_root.MachineGun._y) {
this._y -= walkSpeed;
} else if (_y<_root.MachineGun._y) {
this._y += walkSpeed;
}
}
}
It's clear that the reason he's shaking about is because he keeps being pushed from >_x to <_x of the gun, and it finally settles when it reaches the _x of the gun.
However I've done similar codes before and never had this problem, I have been out of the action script game for a while to be fair.
Any ideas on how to fix/better do this?
Thanks