Page 1 of 1

[SOLVED] bullet collision killing all aliens instead of one

Posted: Fri Oct 16, 2015 5:08 am
by TheKingofJello
when my bullet hits one alien it will automatically kill all aliens to the right of the and above it (starting with the aliens to the right, ending with the actual alien hit).

if you need more info, ask.

Re: bullet collision killing all aliens instead of one

Posted: Fri Oct 16, 2015 5:38 am
by airstruck
I think you forgot a condition in your collision detection, don't you need something like `and b.y > e.y`?

Re: bullet collision killing all aliens instead of one

Posted: Fri Oct 16, 2015 1:39 pm
by bobbyjones
I didn't take a look, but I know I followed tutorials for space invaders and the way I stored the enemies in the table and the way I used table.remove caused me to have a lot of bugs with killing enemies. That might be something worth considering.

Re: bullet collision killing all aliens instead of one

Posted: Fri Oct 16, 2015 5:39 pm
by TheKingofJello
airstruck wrote:I think you forgot a condition in your collision detection, don't you need something like `and b.y > e.y`?
i didn't see that really do anything different then the script it was before I added your suggestion, but thanks for trying to help anyway.

I solved my problem when I realized I was using some iterators and table.remove()s wrong in my collision script.

Re: [SOLVED] bullet collision killing all aliens instead of

Posted: Fri Oct 16, 2015 5:46 pm
by airstruck
Yeah, I suppose if your bullets are always coming from the bottom and the enemies are always coming from the top then the bullet's Y coordinate will always be greater than the enemy's Y coordinate when the X check passes. It still seems strange to leave that out, though (you wouldn't be able to reuse that collision code for much, anyway).

Re: [SOLVED] bullet collision killing all aliens instead of

Posted: Sat Oct 17, 2015 2:14 am
by Beelz
bobbyjones wrote:I didn't take a look, but I know I followed tutorials for space invaders and the way I stored the enemies in the table and the way I used table.remove caused me to have a lot of bugs with killing enemies. That might be something worth considering.
I had an issue like this before and I found counting backwards fixed it... Not sure why, maybe it was a fluke.

Code: Select all

for i=#objects.enemy,1,-1 do
     checkCollision(objects.player,objects.enemy[i])
end

Re: [SOLVED] bullet collision killing all aliens instead of

Posted: Sat Oct 17, 2015 2:20 am
by bobbyjones
Yeah that is a common solution. Many people make a custom iterator for it called reverse ipairs or ripairs I see some people name it as. It because of the way table.remove works.