Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Author
Message
Advancement Games
20
Years of Service
User Offline
Joined: 6th Jan 2005
Location:
Posted: 31st Oct 2005 21:47
Hi,

I have been having some problems with having multiple bullets flying around at once on the screen. I am making an FPS game and I would like it so you can have an unlimited ammount of bullets existing in the game world at once, and it is not working with arrays. Does anyone have any links or code that could do this?
headcrab 53
19
Years of Service
User Offline
Joined: 14th Jul 2005
Location:
Posted: 1st Nov 2005 00:46
What have you tired so far?

Windows XP Service Pack 2 -- Pentium 4 HT 3.0 ghz
1 GB DUAL DDR RAM -- NVIDIA GeForce 6600 GT 128 MB (PCI Express)
re faze
20
Years of Service
User Offline
Joined: 24th Sep 2004
Location: The shores of hell.
Posted: 1st Nov 2005 04:07 Edited at: 1st Nov 2005 04:07
it would probably be in a post around here somewhere more than likely at the bottom in a snippet box

Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 1st Nov 2005 09:28
it should work with arrays.

make an array [bullets(65535)]

make objects [for x = 1 to 65535 : make object sphere x, 1 : next x]

in loop:

[if mouseclick() then inc CurBullet, 1]

position the bullets at where you want them, when the CurBullet reaches 65535, reset it (to 0) and it will continue in a loop.

get the idea?? heh, if you are using DBC, dont use the number 65535, as that is maximum allowed objects in a scene.

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 1st Nov 2005 16:50
You'd be surprised how few bullets you actually need - I mean I found that 200 is plenty when you have about 30 enemies, there's no point in using more memory if you don't have to.

I use Sparky's .DLL for bullets, like I have a few arrays, storing the position, the last position, and the speed of the bullet. Each loop you set the position to the last position and work out the new position based on it's speed - now with 2 locations you can do intersection checks for collision, guage the normal for bullet decals or even the bounce vector ricochets. This is a nice setup because the bullets can be realistically fast, and therefor the bullets don't live long - meaning you can get by with 200. Also, you can hijack your bullet collision check and turn it into a line of sight check for your AI, saving yourself a nice chunk of work .


Van-B

Put those fiery biscuits away!
Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 1st Nov 2005 21:16
Quote: " You'd be surprised how few bullets you actually need "

that is what i mean too, but he said unlimited bullets, so i figured he wanted them bouncing in the scene for ever

Quote: "I mean I found that 200 is plenty when you have about 30 enemies,"

yeah, that sounds reasonable. i usually give my enemies 5 bullets each to use.

Advancement Games
20
Years of Service
User Offline
Joined: 6th Jan 2005
Location:
Posted: 1st Nov 2005 21:28
Yeah, that is the idea lucasw. The game is supposed to have a certain gun that will have the bullets bouncing off walls and tracking objects, and I will have up to 1000 bullets going at one time. I'll try the code out and get back to you on it.
headcrab 53
19
Years of Service
User Offline
Joined: 14th Jul 2005
Location:
Posted: 1st Nov 2005 21:47
Quote: "The game is supposed to have a certain gun that will have the bullets bouncing off walls and tracking objects"


Kind of like a Needler on Halo?

Windows XP Service Pack 2 -- Pentium 4 HT 3.0 ghz
1 GB DUAL DDR RAM -- NVIDIA GeForce 6600 GT 128 MB (PCI Express)
Advancement Games
20
Years of Service
User Offline
Joined: 6th Jan 2005
Location:
Posted: 1st Nov 2005 21:51
Yup. I played halo for the first time at my friend's on friday. It is sick!
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 1st Nov 2005 22:01
I would use a linked list - that way you dont allocate vast amounts of memory for things you wont use. Plus they are easy to get the information out of, easy to delete single items and can be processed quickly.

Come to the third DarkBasic Pro Sci Fi Con - Less than 2 weeks to go!
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
Advancement Games
20
Years of Service
User Offline
Joined: 6th Jan 2005
Location:
Posted: 1st Nov 2005 22:02
I never thought of that. I'll try it out.
Lost in Thought
21
Years of Service
User Offline
Joined: 4th Feb 2004
Location: U.S.A. : Douglas, Georgia
Posted: 1st Nov 2005 22:05
I would write the code to auto-re-use bullets when they die. You could then make as many bullets as you want for your testing and see where the number peaks around. Then just make a little over that number for your final code. It will probably be alot lower than you think.

Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 2nd Nov 2005 01:02
Maybe array insert at top,array insert at bottom, and array delete element could help in reducing and adding if u want to use arrays then u could use


and delete and add when u need to

NARUTO IS THE NINJA.....not really
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Nov 2005 09:54
Adding an array indice or creating an object is not the way to maintain performance - set a limit to the number of bullets you need or suffer, simple as that .

Adding array indices gets slow when you have a lot of indices, like it would create a noticable delay after a while.

1000 bullets flying around is impractical, that's why you'll never see it in even a commercial 3D game.


Van-B

Put those fiery biscuits away!
Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 2nd Nov 2005 15:04
unless you happen to play Age of Empires 3

So you think you're tough? - Zombie Hunter DBPro Beta 1 - December 2005 - Not so tough anymore, huh?
(man, this ad suck!)
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 2nd Nov 2005 15:26
The thing with that though is if it's arrows being fired - well they're probably pre-calculated paths, so really they're just an effect, it's not like you can jump in the air with a frying pan and deflect them.

It's important to stress how much 1000 bullets made from spheres and being collision checked and updated every loop would kill performance - if single figure frame rates are your bag then just ignore me.


Van-B

Put those fiery biscuits away!
re faze
20
Years of Service
User Offline
Joined: 24th Sep 2004
Location: The shores of hell.
Posted: 2nd Nov 2005 15:30
also you should not create and delete objects at runtime because your memory usage will spike.

Lukas W
21
Years of Service
User Offline
Joined: 5th Sep 2003
Location: Sweden
Posted: 2nd Nov 2005 16:03
Van B You are probably right, but the thing is aoe 3 uses real time physics, so the arrows are affected by wind and the likes.

i will not argue since it's not my thread (or duty) we all know that 1000 spheres in dbpro flying around at the same time is bad.

So you think you're tough? - Zombie Hunter DBPro Beta 1 - December 2005 - Not so tough anymore, huh?
(man, this ad suck!)
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 3rd Nov 2005 01:43
i really didn't mean make it with sphere just an example of some sort but i guess it can really slow down adding and reducing arrays

NARUTO IS THE NINJA.....not really
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Nov 2005 09:43 Edited at: 3rd Nov 2005 09:51
I about had a fit when I saw how slow it gets to add indices to arrays, like it starts quite fast, then get's slower and slower.

I think that handling a lot of bullets should be done internally, like not using visible objects, pure maths and collision checks. The thing is, using a point to point bullet path, you don't have to worry about missing targets - line intersect checks are very accurate, and line-circle checks can be used for character bullet collision, you just need the rough radius of each limb on your character.

Personally, I reckon I'd forget about making the bullets visable, I'd use lots of particle effects for when the bullets ricochet - would probably make the game idea a little more difficult, but it's an idea.

Always consider the other factors when deciding on how many bullets you want, ideally keeping the count low. I mean, if you have 25 characters and even just 500 bullets, then your doing 12500 collision checks per loop . So always have a life variable for your bullet, so that you can set a bullet to being dead and can skip collision checks on it. It's a good idea to do a box collision check as well, like if the bullet is close to the character then check for collision, otherwise skip it. It can be real tricky to get smooth bullet handling.


Van-B

Put those fiery biscuits away!

Login to post a reply

Server time is: 2025-05-31 00:52:36
Your offset time is: 2025-05-31 00:52:36