Forum Topic: Following AS2 Help

(42 views • 0 replies)

This topic is 1 page long.

<< < > >>
Sad

Moonhog

Reply To Post Reply & Quote

Posted at: 6/30/09 07:12 PM

Moonhog DARK LEVEL 25

Sign-Up: 07/31/04

Posts: 4,382

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

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 12:06 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!