# Ballistic

**URL:** <https://forum.kirupa.com/t/ballistic/183907>\
**Category:** open source\
**Created:** [March 31, 2006, 2:55am UTC](https://forum.kirupa.com/t/ballistic/183907 "2006-03-31T02:55:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darkfuzz](https://avatars.discourse-cdn.com/v4/letter/d/82dd89/32.png) [@Darkfuzz](https://forum.kirupa.com/u/Darkfuzz)\
**Post date:** [March 31, 2006, 2:55am UTC](https://forum.kirupa.com/t/ballistic/183907/1 "2006-03-31T02:55:21Z")

</div>

I’m working on a simple 2-d space shooter called Ballistic (name pending :+)).

I got the spaceship’s movement down pretty good, and same with the weapons system, but when it came to blowing up asteroids, I’m having an unusual amount of trouble.

I keep every bullet movieclip in an array for easy management, so to program the asteroid to be hit by the bullets, I wrote this:

```auto

onClipEvent(load){
    var hp = 20;
}

onClipEvent(enterFrame){
    for(i=0;i<10;i++){ //runs through shot array (its only 10 spaces long)
        if(this.hitTest(weapon.sf*._x,weapon.sf*._y,true)){ //weapon.sf is the bullet array (weapon is a global object that holds information about the weapon being used)
            hp--; //decrement asteroid hp
            weapon.sf*.removeMovieClip(); //removes bullet once it touches the asteroid
            weapon.sf* = 0; //makes an "empty" spot in the array that can be filled with another shot
        }
    }
}

```

So as you can see, when the asteroid’s surface area touches the exact x,y point of the bullet, it loses 1 hp.

Well, for some ungodly reason, if I fly the ship about 150 pixels to the lower right of the asteroid, the asteroid thinks it’s losing 1 hp every frame, and in a matter of seconds it’s at -6,000 hp.

I’ve traced the weapon.sf array to see what is inside it when I fly to that point, and it says nothing. So, somehow the asteroid thinks there is a bullet touching it when there is actually no bullet, and nothing is touching it.

Now, if I switch it around and use  
if(weapon.sf.hitTest(this)){  
it seems to work fine, but then I get the cheesy effect where the bullet doesn’t actually touch the asteroid and still dissapears.

I know that there must be a way around this. It’s not like this is the first time I’ve used a hitTest in my games…:h:

The files are attached if you care to look through them. If anyone can figure this out, that would be awesome.

Thanks!  
 [http://darkfuzz.com/flash/ballistic2.fla](http://darkfuzz.com/flash/ballistic2.fla)  
 [http://darkfuzz.com/flash/ballistic2.swf](http://darkfuzz.com/flash/ballistic2.swf)  
 a = turn left  
d = turn right  
w = boost  
s = brake/reverse  
click = fire

df :?)

---

<div class="post-metadata">

**Author:** ![theflash](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/theflash/32/1221_2.png) [@theflash](https://forum.kirupa.com/u/theflash)\
**Post date:** [March 31, 2006, 5:20am UTC](https://forum.kirupa.com/t/ballistic/183907/2 "2006-03-31T05:20:21Z")

</div>

hitTest basically checks for area bound rectangles for intersection… try using hitTest with point and not the MC
