# More shooting woes, lack of a hitTest

**URL:** <https://forum.kirupa.com/t/more-shooting-woes-lack-of-a-hittest/176521>\
**Category:** programming\
**Created:** [January 24, 2006, 7:12pm UTC](https://forum.kirupa.com/t/more-shooting-woes-lack-of-a-hittest/176521 "2006-01-24T19:12:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sammo](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/sammo/32/779_2.png) [@Sammo](https://forum.kirupa.com/u/Sammo)\
**Post date:** [January 24, 2006, 7:12pm UTC](https://forum.kirupa.com/t/more-shooting-woes-lack-of-a-hittest/176521/1 "2006-01-24T19:12:03Z")

</div>

```auto
load1_1 = load2_1 = load1_2 = load2_2 = true;
function shoot (player, gun, maxSpeed) {
	mc = _root["player"+player];
	j = (1+j)%1000;
	_root["load"+player+"_"+gun] = false;
	switch (gun) {
		case 1:
			b = attachMovie("bolt","bolt"+j,j+11000);
			xp = 5;
			break;
		case 2:
			b = attachMovie("missile","missile"+j,j+11000);
			xp = 30;
			break;
	}
	b.gotoAndStop(player);
	b._x = mc._x, b._y = mc._y, b._rotation = mc._rotation;
	b.speed = mc.speed+5;
	if (!_root["load"+player+"_"+gun]) {
		_root["loading"+player+"_"+gun] = setInterval(loadGun, 300, player, gun);
	}
		b.onEnterFrame = function () {
		this.speed++;
		this.speed *= maxSpeed, this.rad = this._rotation * (Math.PI / 180);
		(this._y <= 0 || this._y >= 500 || this._x <= 0 || this._x >= 650) ? this.removeMovieClip() : null;
		this._x += Math.sin(this.rad) * this.speed;
		this._y -= Math.cos(this.rad) * this.speed;
		if (this.hitTest(_root["player"+mc.num]._x, _root["player"+mc.num]._y)) {
			this._visible = false;
		}
	}
}
function loadGun (playno, g) {
	_root["load"+playno+"_"+g] = true;
	clearInterval(_root["loading"+playno+"_"+g]);
}

```

Big nasty shoot function there. All works fine, both the bolt MC and the missle MC spawn and move correctly, and if they hit the other ship, the disappear, however if I shoot and move the shooting ship (which is prone to happening a lot in a 2-player shoot 'em up) the hitTest just stops working. I have no idea why.

The ships move like so:

```auto
MovieClip.prototype.mover = function(speedStop, remove) {
	this.speed *= speedStop, this.rad = this._rotation * (Math.PI / 180);
	if (remove) {
		(this._y <= 0 || this._y >= 500 || this._x <= 0 || this._x >= 650) ? this.removeMovieClip() : null;
	} else {
		this._x <= 0 ? this._x = 650 : this._x >= 650 ? this._x = 0 : null;
		this._y <= 0 ? this._y = 500 : this._y >= 500 ? this._y = 0 : null;
	}
	this._x += Math.sin(this.rad) * this.speed;
	this._y -= Math.cos(this.rad) * this.speed;
};

function moveShips() {
	Key.isDown(Key.UP) ? (player1.speed++, player1.smoke()) : Key.isDown(Key.DOWN) ? (player1.speed -= .25, player1.smoke(20)) : null;
	Key.isDown(Key.LEFT) ? player1._rotation -= 5 : Key.isDown(Key.RIGHT) ? player1._rotation += 5 : null;
	Key.isDown(96) ? ((load1_1) ? shoot(1, 1, .92): null) : Key.isDown(110) ? ((load1_2) ? shoot(1, 2, .90) : null) : null // 0 and .
	player1.mover(.89);
	//
	Key.isDown(87) ? (player2.speed++, player2.smoke()) : Key.isDown(83) ? (player2.speed -= .25, player2.smoke(20)) : null;
	Key.isDown(65) ? player2._rotation -= 5 : Key.isDown(68) ? player2._rotation += 5 : null;
	Key.isDown(Key.SPACE) ? ((load2_1) ? shoot(2, 1, .93) : null) : Key.isDown(70) ? ((load2_2) ? shoot(2, 2, .90) : null) : null // space and F
	player2.mover(.89);
	//
}
_root.onEnterFrame = moveShips;

```

.swf attached.

PS. Kirupa and/or mods, why is the .fla upload max size so low? (too low for fla’s IMO)
