I have bullets in my project set as fast collision bodies. They expire on collision if not set to ricochet, marking themselves for removal at the end of the simulation turn (after collision update). When they collide with a non-static object, they will apply an impulse if they ricochet, but apply no impulse if they expire instead. It's almost like the collision impulse doesn't "take effect" until the next step, so removing the bullet collision body stops the impulse from applying.
That might also explain why the collision body linear velocity doesn't reflect the updated velocity while checking contacts with contact manifolds. I tried making bullets reorient to the new velocity on impact, but the velocity didn't seem to change until later.
I'm probably handling the collision contact and contact manifold wrong. I treat that as an indication that the objects have just collided and been updated. I suspect that it's actually an indication that the objects will collide at the next step, so deleting one of them prevents the collision impact from taking effect.
I assume you are working from the SVN version.
I plan on fixing this. I will be applying an impulse at the time of impact instead of waiting for the next step.
Ah, okay. That would explain it.
I did notice it started when I updated to the SVN version with CCD. I use so many fast-moving projectiles that I needed to use that one instead of the normal one, but it's not like the lack of bullet impact is going to cause too many problems for now. It's just a feature that I happened to like and that came along for free. 😎
(I'm definitely looking forward to collision callbacks, as that will eliminate the need for my hacky application-side version. Still, my hacky application-side callbacks work, so there's no hurry.)
Bullets are a great application for CCD. CCD and contact callbacks are coming for version 2.0.
I remember seeing that in the TO DO list and looking forwards to them. Getting the "pre-release" version from SVN has already been useful, occasional broken builds aside. 😁
Once my project stabilizes a bit, I should add an entry to the "Games and Applications" forum. It doesn't show off Box2D as openly as some of the other physics demos, but it does use it. I'll be able to create a lot more obviously "physics-y" stuff when I finish adding support for joints to the XML level loader. (That'll take some doing, as I need to find a way to handle the separation between configuration and instantiation. Joint definitions currently don't support that so I have to find a workaround.)
That is also on the TODO list for 2.0. I will move to a system where joints are defined in local coordinates. This will let you use the same joint definition no matter the configuration of the bodies.
I'll have to see how that works once it's done. Right now the problem is that the joint definition requires two collision bodies already added to the world. My object system doesn't add the collision bodies to the world until after the instance object is done loading, and the collision bodies of template objects never get added to the world. My partially-done version hacks name hashes into the body pointers in the joint definition, to be replaced with actual collision body pointers on instantiation.
The "set it and forget it" shape definitions you have planned will definitely neaten up the collision body side, so I'll be able to get rid of the data vectors holding the shape definitions.
The biggest hang-up right now is that I can't decide how to handle "composite" collidables. My current setup has one "main" collision body that represents the core of the entity, with its transform and velocity updating the entity versions. I currently have other collision bodies as named elements in the collidable, and joint definitions referencing those "local" elements. Unfortunately, those "local" elements would not exist as far as the rest of the game is concerned, so I'll need to allow joint definitions referencing "global" elements as well, allowing cross-linked entities. In most cases, this would take place at the template level, with referenced template chain-instantiated from the core template. None of this really concerns Box2D, though, so it's technically irrelevant to this forum... 😎
By the way, what's the best way to attach two separate collision bodies together as if they were a single body? They need to stay separate bodies because they're separate game entities, but I don't want them wiggling around even during aggressive maneuvers. I tried a prismatic constraint with motor, but I had to help it along by applying impulses during simulation. That works fairly well, but still wonks out at low simulation rates.
So you need some pointer fixup on loading joint data. This is typical. You can cast the body pointers into some index into a central lookup table. Or you can wrap the b2JointDef inside some other data structure that carries the needed body references.
Two entities sharing a single rigid body? Each entity is a separate shape? If so, then you can use the shape user data to find your entity and put all the shapes on a single rigid body.
Welding bodies together should be a last resort. Box2D has an iterative solver, so you won't get something completely solid. You would also have performance hit.
Use a revolute joint with equal limits to make a weld joint. I'll make a better weld joint in the future.
I got the fix-up process working, though it's somewhat hacky. I store a structure containing the entity name and body name for each end of the link in a list, and save a pointer to it in the userData of the joint descriptor. On instantiation, I extract that structure, look up the entities and bodies, fill in the body pointers in the descriptor, and transform anchor points to world coordinates. It worked well enough to remove the hard-wired joints between the main ship and the four drone ships in formation, so that's already a marked improvement. 😀
Prismatic has been working reasonably well now that I figured out I was probably using it wrong. I wasn't sure where to set the anchor point for revolute and prismatic joints, so I used the center of the main ship. However, they seemed to behave better when I used the center of the drone ship instead, working mostly fine down to 10Hz with 16 iterations (wobbling slightly). Previously, the joint would freak out below 15Hz and completely wreck the formation. They also seem stuck on much more firmly, whereas colliding them into obstacles previously pushed them out of formation as if they were mounted on springs. To an extent, that was a good thing, but being able to eliminate my "wiggle fix" ApplyImpulse hack is more than worth it.