View Full Version : Tracking Projectiles?

06-05-2002, 04:39 PM
What is the standard model for keeping track of projectiles?

You have object with their own coordinates and bounding box. Then how do you handle the creation and deletion of projectiles?

I understand the collision detection part.

Any information or websites would be appreciated. Thanks.

06-05-2002, 05:02 PM
I'm not an expert, but you have two options. One is an array. The problem here is that reallocating it could be a pain because you need to recopy all the data, if you know there won't be more than some number of projectiles you could keep it at some constant size, but thats memory innefficient
Probably better is to use some sort of linked tree, like an octree or an AABB tree. These would speed collision detection and are easy to insert into and delete from on the fly

06-06-2002, 05:41 AM

what I did was forking a process which moved each projectile. That is not a clean but a working solution. I then specified a callback func which handeled collisions with target or ground.

The other thing you could do, which is better, as I figured out, is to create a linked list and walk through it in every draw frame and update the coords. If you hit something you know which hit and you can delete it and link the next to next->next (if you do C or C++). That is pretty fast and your frame rate should drop max. 1 frame. That is what happened when I implemented something like that. I had a drop of 2 frames after firing 1.000 projectiles (each 34 polys) on my GeForce2 GTS.