Best way to avoid collision between a bullet and its gun?

Hi, I'm trying to prevent a bullet from colliding from it's origin. Right now I'm using a contactCallback (generated within the bullet, so one for each bullet, will change to a single hash map for all bullets). I've also been looking at CollisionGroups and now I'm left wondering which one is the fastest. Also, both these methods have a slight drawback, bullets will never be able to hit the gun (this won't usually happen, but I'd prefer for it to be possible in theory for when bullets bounce off or are shot right up or whatever weird things I decide to make later on). To fix this I thought it'd best to make a custom UpdateCallback to check for the distance between the bullet and the gun and make the bullet collidable only after a certain distance from the gun is reached. This Callback could then remove itself after activating the bullet. However it leaves me wondering how it will behave when a lot of bullets are fired at once and a lot of callbacks will be removed at once. If all else fails I can make the "gun" add a given Vector3f to it's coordinates before passing them to the bullet for launch. That way the bullets will originate in front of the gun, avoiding collision. However I do feel this method is just 1337 h4ckz and may give problems.

So, what method do you guys think is best? (for speed or otherwise)

  1. ContactCallbacks
  2. CollisionGroups
  3. UpdateCallbacks
  4. Move origin

    Please comment.

I would think moving the origin to just away from collision with the gus is the best. As you mention, you don't want any post processing once you fire a bullet to add/remove callback or anything. And even if it is simply an if statement, when you have to make the call to check for distance every frame, plus a potential call to remove it then it piles up. Besides, that has the conceptual behavior you want, I believe: the bullet doesn't really hit anything unti it is out of the gun.

Generally there should be a broadphase level filtering callback that would allow you to ignore the shooting entity. ContactCallbacks are probably narrowphase so you might want to avoid it.

Well, I thought about it some more and I'll go with the origin moving, with big and slow bullets (that should not pop-out in front of a gun) I'll just go with realism and make the gun actually hollow inside. Probably takes about 48 more faces (using 12 sided cilinders), seems faster than all the checks.

place the bullets at the muzzle (front of the barrel), not inside the gun, fast travelling bullets should do ok, otherwise just ignore the collision with the originating gun (the bullet has a originator? player, or so? so you know who fired it and so who scored the hit?)

bullets vs. bullets, in fast shooters ignore bullet to bullet hits, if this is a game with slow bullets and intended to do so, you need an delay for the placement of new bullets, based on the travelling speed of your bullets (don't place the next bullet until the first is far enough away).