Page 1 of 1
managing bullets
Posted: Sun Jul 11, 2010 7:17 pm
by WSPSNIPER
hi i was thinking about how i was going to handle bullets in a game im writing. i use to just do a for loop checking every bullet against every entity and i was wondering if you had a faster method of doing this. it is going to be a top down shooter so the bullets will be traveling in different directions. thanks for your time
Re: managing bullets
Posted: Sun Jul 11, 2010 8:12 pm
by Ginto8
look up quadtrees. That is all.
Re: managing bullets
Posted: Sun Jul 11, 2010 8:51 pm
by hurstshifter
Do a search for things like "handling bullets" or "projectiles". I've seen many topics like this one on this forum in the past year or two. If I can find any I will post the links.
Re: managing bullets
Posted: Sun Jul 11, 2010 9:08 pm
by WSPSNIPER
Ginto8 wrote:look up quadtrees. That is all.
Thanks
Re: managing bullets
Posted: Sun Jul 11, 2010 10:25 pm
by eatcomics
Make sure you always have a full clip in your weapon, and make sure you have at least 3 other fully loaded clips on you. Hopefully you also have an emergency side arm, I have found this to be the best method of bullet management, and it is highly effective against the zombie menace
Re: managing bullets
Posted: Sun Jul 11, 2010 11:40 pm
by ibly31
Haha eatcomics, thats what I thought he was talking about. When I first saw this I'm like "WTF, uuhmm, aim for heads, dont spray..." isn't that kind of obvious?
Re: managing bullets
Posted: Mon Jul 12, 2010 10:52 pm
by WSPSNIPER
eatcomics wrote:Make sure you always have a full clip in your weapon, and make sure you have at least 3 other fully loaded clips on you. Hopefully you also have an emergency side arm, I have found this to be the best method of bullet management, and it is highly effective against the zombie menace
lol, im sorry i may not have clearly stated the question. i ment managing bullets as in handling collisions and such in the code...
Re: managing bullets
Posted: Tue Jul 13, 2010 2:38 pm
by eatcomics
I knew what you meant, but it was late and i thought someone explained it... just look on this forum and on google there are a LOT of tutorials on the subject, once you wrap your head around it it becomes second nature... But I could be more helpful if you would explain what kind of game you are doing? Like a 2D space shooter or 3D FPS and so on
Edit: oh you said top down shooter... really I think your method should be efficient enough, but as ginto said quadtrees would be helpful as well
Re: managing bullets
Posted: Tue Jul 13, 2010 7:47 pm
by Ginto8
eatcomics wrote:really I think your method should be efficient enough, but as ginto said quadtrees would be helpful as well
It could be. But as there are probably going to end up being both a large number of bullets and entities simultaneously active, the chances of a naive bruteforce being efficient is low. A correctly populated and sorted quadtree can significantly reduce the number of collision tests he does, and will also be a good learning experience (quadtrees and their 3D companions octtrees are used a ton in game dev).
Re: managing bullets
Posted: Tue Jul 13, 2010 9:01 pm
by eatcomics
yep, and I didn't even know about them until recently... But you are certainly right that is why I suggested it along with you. and there are ways you could optimize it to only check things on screen and such if that's what you want, but quad trees are definitely my suggestion
Re: managing bullets
Posted: Tue Jul 13, 2010 10:07 pm
by Ginto8
eatcomics wrote:yep, and I didn't even know about them until recently... But you are certainly right that is why I suggested it along with you. and there are ways you could optimize it to only check things on screen and such if that's what you want, but quad trees are definitely my suggestion
Well unless things are only alive when they're on the screen, you want to check more than just the screen, because otherwise you can have all sorts of mess ups with the game logic (for example, you walk away from an NPC and the npc walks into/through a wall, and suddenly your collision has a seizure when it comes back onscreen because it doesn't know how to handle it).
Re: managing bullets
Posted: Wed Jul 14, 2010 2:25 pm
by eatcomics
this was about bullet collision, not NPC I was suggesting just deleting them offscreen. That's also not foolproof but it would work, and for some game types that's the way it should be done
edit: but to elaborate, for your needs quadtrees would be the best solution