Setting up bullets
Objects usually move slow enough to stop before passing through walls. However, some objects might move so fast that they teleport through obstacles. This is especially true for bullet type objects. You can eliminate this problem by letting Box2D know that these objects should be treated as bullets. Some games use a ray-casting technique where you basically determine the point of the bullet's impact on a wall or another object. This usually assumes a bullet trajectory in a straight line, which is not very accurate when compared to the real world.
Getting ready
For this recipe, you'll need to have one dynamic object, bullet, and one static object, wall to build a sample scene. For this purpose, you can use the following code:
local function createBullet(position, radius) local body_def = box2d.BodyDef() body_def.type = 'dynamic' body_def.position = position * box2dScalingFactor body_def.angle = 0 local body = world.createBody(body_def) local shape = box2d.CircleShape...