I was trying to get a bullet to collide with a bug(enemy) on the stage. The bullet_mc had a small animation which shape tweened the bullet into a splash.
I wanted this animation to play when the bullet hit the enemy and appear on top of the bug, to depict that the bug had been squatted by the bullet.
So I detected the collision using hitTestObject , stopped decrementing the Y for the bullet (To stop it from
moving upwards) , and called the bullet_mc.play() function on an active collision to play the splash animation.
But, I ran into some problems. Since, the hitTestObject works with bounding boxes, my bullet was colliding with the enemy a little too soon.This was because a collision took
place as soon as the top of the bullet bounding box hit the bottom of the enemy box (Yeah, my enemy was on top, the bullet came from below). Thus, when the bullet_mc.play()
was called, the splash appeared out of place (where the mc had stopped) rather than on top of the bug (where I wanted it to 🙂 ).
The solution was pretty simple and an obvious one, but I still had to find it on IRC :P. I made a tiny 1 px by 1px mc inside the bullet_mc. Then instead of detecting a collision between bullet_mc and the enemy_mc, I
detected a collision between this tiny MC and the enemy_mc. With a little tweaking in the position of the tiny_mc inside bullet_mc, I was able to play my animation on top of the bug
like I wanted :).