Simulate gun bullets with high speed collision misses

Post Reply
gokoon
Posts: 9
Joined: Fri Jan 27, 2012 10:57 am

Simulate gun bullets with high speed collision misses

Post by gokoon »

What is the proper way to simulate bullets ?
I want those bullets to be not instantaneous, and since they are known to travel fast and have little if not punctual size, there can be collision misses.

One single raycast will not be enough, should I raycast once per step to check if the bullet went through an object ?
The trajectory can be a straight line, but applying gravity would be nice and some sort of random wind would be good too.
I also am not looking for bullets to go through multiple targets.
User avatar
dphil
Posts: 237
Joined: Tue Jun 29, 2010 10:27 pm
Contact:

Re: Simulate gun bullets with high speed collision misses

Post by dphil »

Continuous collision detection is what you really want for this sort of thing, but I'm not sure what state Bullet's CCD side is in. I've never used it myself.

Otherwise, you could approximate it with per-step raycasts as you mention. I'm not sure if the trajectory (straight line, arc, etc) of the bullet over time wouldn't matter in this case, as the motion during each individual step would presumably be a straight line (I believe) based on the total calculated forces for that step, and thus amenable to raycasting the bullet's traversal for that step. Though straight linear motion per-step may not be the case with simulation substeps...? But if the trajectory was restricted to a straight line, then iterative raycasts would work fine in any case.
Keep in mind though that this approach will still make erroneous hits/misses in some cases, such as when an object is just entering or leaving the bullet's next path segment. Though given that the objects you care about the bullet hitting are presumably much larger and slower than the bullet, it shouldn't be a commonly occurring issue, and may not matter for your purposes anyway.
Post Reply