[SOLVED] bullet collision killing all aliens instead of one

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
TheKingofJello
Prole
Posts: 4
Joined: Mon Aug 17, 2015 11:28 pm

[SOLVED] bullet collision killing all aliens instead of one

Post 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.
Attachments
invaders.love
(46.27 KiB) Downloaded 86 times
Last edited by TheKingofJello on Fri Oct 16, 2015 5:37 pm, edited 1 time in total.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

Re: bullet collision killing all aliens instead of one

Post by airstruck »

I think you forgot a condition in your collision detection, don't you need something like `and b.y > e.y`?
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: bullet collision killing all aliens instead of one

Post 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.
User avatar
TheKingofJello
Prole
Posts: 4
Joined: Mon Aug 17, 2015 11:28 pm

Re: bullet collision killing all aliens instead of one

Post 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.
User avatar
airstruck
Party member
Posts: 650
Joined: Thu Jun 04, 2015 7:11 pm
Location: Not being time thief.

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

Post 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).
User avatar
Beelz
Party member
Posts: 234
Joined: Thu Sep 24, 2015 1:05 pm
Location: New York, USA
Contact:

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

Post 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

Code: Select all

if self:hasBeer() then self:drink()
else self:getBeer() end
GitHub -- Website
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

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

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests