# Bullet hitTest problem

**URL:** <https://forum.kirupa.com/t/bullet-hittest-problem/195479>\
**Category:** programming\
**Created:** [August 1, 2006, 2:40am UTC](https://forum.kirupa.com/t/bullet-hittest-problem/195479 "2006-08-01T02:40:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![LordArkain](https://avatars.discourse-cdn.com/v4/letter/l/f07891/32.png) [@LordArkain](https://forum.kirupa.com/u/LordArkain)\
**Post date:** [August 1, 2006, 2:40am UTC](https://forum.kirupa.com/t/bullet-hittest-problem/195479/1 "2006-08-01T02:40:49Z")

</div>

Need some help on my bullet hitTests. My bullets are not working when they hit the enemy. I have only managed to get the bullets to do what they are supposed to once. Here is my code and fla. The bold part is the bullet hitTest.

```auto

stop();
//enemy scripts
enemy.onEnterFrame = function() {
 if(this._x<hero._x){
  this._x+=2;
 }
 if(this._x>hero._x){
  this._x-=2;
 }
 if(this._y<hero._y){
  this._y+=2;
 }
 if(this._y>hero._y){
  this._y-=2;
 }
 **if(Bullet[Num].hitTest(this)){**
 **this._x-=40;**
 **this._y-=40;**
 **}**
}
//hero scripts
Num = 0;
hero.onEnterFrame = function() {
 //movement script
 if(Key.isDown(Key.LEFT) || Key.isDown(65)){
  this._x-=4;
 }
 if(Key.isDown(Key.RIGHT) || Key.isDown(68)){
  this._x+=4;
 }
 if(Key.isDown(Key.UP) || Key.isDown(87)){
  this._y-=4;
 }
 if(Key.isDown(Key.DOWN) || Key.isDown(83)){
  this._y+=4;
 }
 //angle script
 var x:Number = _xmouse-this._x;
 var y:Number = _ymouse-this._y;
 var angleRad:Number = Math.atan2(y, x);
 var angleDeg:Number = angleRad/Math.PI*180;
 this._rotation = angleDeg;
};
ShootBullet = function () {
 var Bullet = _root.attachMovie("Bullet", "Bullet"+Num, _root.getNextHighestDepth());
 var point = {x:this.hero.gunTip._x,y:this.hero.gunTip._y};
 this.hero.localToGlobal(point);
 Bullet._x = point.x;
 Bullet._y = point.y;
 Bullet._rotation = _root.hero._rotation;
 Bullet.onEnterFrame = function() {
 Bullet._x += Math.cos(Bullet._rotation*(Math.PI/180))*25;
  Bullet._y += Math.sin(Bullet._rotation*(Math.PI/180))*25;
 };
 Num++;
};
hero.onMouseDown = function() {
 ShootBullet();
};
 

```

I have tried multiple ways to get it to work but can’t seem to get it to work. The one way it worked is if I change Bullet[Num] to Bullet1. But it only works on the first bullet (actually second bullet because it seems to count the first as 0).

[COLOR=red]EDIT NOTE[/COLOR]: Btw, why don’t swf files work on the upload section???
