Box2d 在碰撞时移动另一个 body 之前移除 body

Box2d removing body before it moves another body upon collision

两个动态物体发生碰撞,我想在它与另一个碰撞时移除一个(一颗子弹)。我根本不希望子弹推另一个body。它应该在物理交互之前被删除。我应该在哪里放置删除代码?

你可以make it a sensor:

A fixture can be made into a 'sensor' by setting the isSensor member of the fixture definition to true when you create it, or by calling SetSensor(bool) on the fixture after it has been created if you need to change it during the simulation. Sensors behave as if their maskBits is set to zero - they never collide with anything. But they do generate BeginContact/EndContact callbacks to let us know when they start or stop overlapping another fixture.

然后您将获得所有碰撞检测,但 none 物理后坐力。