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.
[SOLVED] bullet collision killing all aliens instead of one
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- TheKingofJello
- Prole
- Posts: 4
- Joined: Mon Aug 17, 2015 11:28 pm
[SOLVED] bullet collision killing all aliens instead of one
- 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.
Re: bullet collision killing all aliens instead of one
I think you forgot a condition in your collision detection, don't you need something like `and b.y > e.y`?
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: bullet collision killing all aliens instead of one
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.
- TheKingofJello
- Prole
- Posts: 4
- Joined: Mon Aug 17, 2015 11:28 pm
Re: bullet collision killing all aliens instead of one
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.airstruck wrote:I think you forgot a condition in your collision detection, don't you need something like `and b.y > e.y`?
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
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
I had an issue like this before and I found counting backwards fixed it... Not sure why, maybe it was a fluke.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.
Code: Select all
for i=#objects.enemy,1,-1 do
checkCollision(objects.player,objects.enemy[i])
end
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: [SOLVED] bullet collision killing all aliens instead of
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.
Who is online
Users browsing this forum: Bing [Bot] and 7 guests