Page 1 of 1

projectile help

Posted: Sat Oct 12, 2019 9:25 am
by Crossing
Hey guys making a little game and having some trouble with the bullets. never really done anything shooter related and having trouble making some code to shoot, detect, and remove bullets. If you spam click and just click around you'll notice some bullets disappear for no reason. also for some reason i get occasional stutters anyone know why?



note a lot of aliens might go to the earth (its random chance) just testing the collision, which is the same thing i used for the projectiles but no problems like the projectiles?

Re: projectile help

Posted: Sat Oct 12, 2019 10:26 am
by pgimeno
Crossing wrote: Sat Oct 12, 2019 9:25 am note a lot of aliens might go to the earth (its random chance) just testing the collision, which is the same thing i used for the projectiles but no problems like the projectiles?
No, it's not the same thing.

To mark the aliens for deletion, you use: table.insert(RaidHit, i) but for the bullets, you use: ProjectileTrash[i] = i. The latter is not correct, because the index of the bullet is not valid as an index into the ProjectileTrash array. It creates holes in the ProjectileTrash array; you're lucky it works at all.

You can use table.insert, like with the aliens, or you can use a variable that you initialize with zero, and tells you how many elements are there in the ProjectileTrash array.