Monster Racer Rush
Select between 5 monster racers, upgrade your monster skill and win the competition!
4.18 / 5.00 3,534 ViewsBuild and Base
Build most powerful forces, unleash hordes of monster and control your soldiers!
3.80 / 5.00 4,200 ViewsSo i'm working on a platforming game, and i can't get my bullets to collide with my enemies properly.
Here's what i'm using:
for(i=0;i<99;i++){
if (_root["enemy"+i].hitTest (_root["bullet"+i]._x, _root["bullet"+i]._y, true)){
_root["bullet"+i].removeMovieClip();
}
}
This works fine on the walls, but not enemies. Is it because they're both using the same variable"i"? I tried adding another "for" loop to see if i could give a different variable to the bullets, but the test lagged so bad i couldn't even see if it worked =(
The strange thing is the collision does work once, but only on the enemy at the edge of the map. After that one shot works the rest just go right through, it's driving me crazy!
You are right about it being because they are using the same iterator 'i', see in this case you test if enemy1 is touching bullet1, if enemy2 is touching bullet2 and so on like that only testing one bullet against one enemy. Like you said to test them all you'll need a loop within a loop, if that lags too much then you'll have to come up with an alternate method to do your hitTesting, such as seperating the objects into areas and only testing against ones which are within a certain range of each other.
.
At 10/19/10 09:13 PM, Fion wrote: You are right about it being because they are using the same iterator 'i', see in this case you test if enemy1 is touching bullet1, if enemy2 is touching bullet2 and so on like that only testing one bullet against one enemy.
Thanks man, i think i got this now =)