Most Efficient hitTest

Hey everybody.

So I’m doing my first complicated game (a megaman game) and I’m wondering what’s more efficient for hit detection. Right now my megaman clip has an enterFrame action which is controlling all of his movement and that works well, and the hit detection for the walls and enemies and such were enterFrame actions on the individual objects.

Should I keep all the hit Detection in the megaman clip and loop through arrays to check collisions or should I keep it on the individual objects.

I’m worried that too many enterFrame actions will slow the game down, but I want to keep megaman’s code down to a minimum as well.

If you have some experience with this please let me know what you think is the best way to go about this.

Thanks to anybody willing to help,

–Patrick

I can’t imagine that testing for x number of hit tests would slow things down any more or less based on which clip(s) was doing the testing, if it was the same number of tests being done. One clip testing for 10 enemy hits or 10 enemies testing for one shouldn’t be any different - maybe others can confirm that point. I do think it’s easier to put the hit test in the enemies, though - for one thing, if you have points in the game where there are five enemies (and not ten) onscreen at once, the game would run faster with less enemies testing for hitting the main player, rather than having the player’s movie clip testing for all the enemies.

Make sense? Post a link or fla if you can.

in terms of effency, you should keep all objects of the same type (type as far as hittest is concerned) in one movieclip. This way, to check a hittest from one object to many, all you need to do is check the one object (or point, really) and a hit test with the movieclip containing the many.

For example, megaman would be in one movieclip and a bunch of bad guys would be in another. To check if megaman hit a bad guy, just check his position with a hit test on the movieclip containing the bad guys. If that returns true, then you can take the extra step of finding out which one, but that only when true and not every single frame of game play.

Otherwise, if you stick to bounding box hittests, you’ll have a much faster hit test but you’ll need to loop through every possible object thats possible to be hit and perform the test on each one. You may also find that actual movie clip bounding areas are too big (hittest will return true even when they are not touching) so you may want to give them each separate invisible boxes within themselves to represent a bounding box for hittest and use those in the calculations. Now you may get some contact that doesnt register this way but close calls are better than "Hey, he didnt even touch me!"s.

Thanks guys.

Senocular, I’ve been taking your approach so far. Currently, the weapon firing is of the “many things in one movie clip” variety and the platforms are all separate hit tests with bounding boxes because they are square.

I’ll make sure to post the link to the game when it’s done.

Thanks guys, I appreciate the input.

*edit, oh and yeah, i was using an invisible hit test box for megaman’s hit detection. I think i’m on the right track with this.

:slight_smile:

–Patrick

wait so how would u do that hittest ur talking about?

i dun really understnad it…

im doing something similer… making a mario game