Fast small Bullets

Hi,
in my game I have bullets that are small and fast. Of course they have isBullet set but sometimes they still move through other shapes, especially edge shapes (because they have no area and are only tested on the borders, I know). But I don't want to miss the edge shapes. Instead I want to use the bullets' last 10 positions to be used for collision, too. This way they will be recognized more likely. But I can't use a static thin rectangle as a shape, since bullets may bounce off the terrain like this:
Code:
        o
\     /
  \ /
---------


So I would need to use segments. But segments are no shapes so I can't attach them to the bullet body. And then the problem arises that I don't want those segments to bounce themselves because they should just follow the bullet. Is this what sensors are for? But how to use the segments as sensors, then?
IsBullet will completely prevent shapes from travelling through one another - this is one of the major features of Box2D. If this isn't the case, then something is wrong in your code or Box2D. I suggest you check b2Body.IsBullet to make sure it is actually enabled, and that continuous phsyics is (b2World.SetContinuousPhysics).
Yes, both are enabled but it still does happen. I don't think I have to set isBullet for the static shapes as well. Maybe the continuous physics don't work with edge shapes? Because with normal polygons the bullets never go through.
It ought to work, I believe.
If you can reproduce the problem in a form I can can examine (i.e. preferably a modified testbed) I'll take a look, though I recommend you eliminate any other source of problems first, such as upgrading to the latest version etc.
I'm using Blaze, box2d for D, and I have the latest version of it.
I can write an example with Blaze.
Judging by the Blaze commit log, I take it this has been resolved? Was it just a porting issue?
That bug was a porting issue, yes. But that one has nothing to do with my current problem.
So it is not resolved 😉
I made a small test case. This is the code:

Code:
module edgetest;

import arc.all, blaze.all;
import derelict.sdl.sdl;

void main() {
   double pxPerM = 30f;
   
   // create world
   bzAABB worldAABB;
   worldAABB.lowerBound.set(-100 / pxPerM, -100 / pxPerM);
   worldAABB.upperBound.set((800 + 100) / pxPerM, (600 + 100) / pxPerM);
   auto gravity = bzVec2(0.0f, 5.0);
   bool doSleep = true;
   auto world = new bzWorld(worldAABB, gravity, doSleep);
   world.continuousPhysics(true);
   auto wallShapeDef = new bzEdgeDef;
   wallShapeDef.friction = 0.6;
   wallShapeDef.restitution = 0.1;
   wallShapeDef.vertices.length = 4;
   wallShapeDef.vertices[0] = bzVec2(0, 0) / pxPerM;
   wallShapeDef.vertices[1] = bzVec2(50, 0) / pxPerM;
   wallShapeDef.vertices[2] = bzVec2(50, 400) / pxPerM;
   wallShapeDef.vertices[3] = bzVec2(0, 400) / pxPerM;
   auto wallBodyDef = new bzBodyDef((bzVec2((800 - 50) / 2, (600 - 400) / 2) / pxPerM), 0);
   auto wallBody = world.createBody(wallBodyDef);
   wallBody.createShape(wallShapeDef);
   
   
   // create bullet
   auto objectShapeDef = new bzPolyDef;
   objectShapeDef.setAsBox(5 / 2 / pxPerM, 5 / 2 / pxPerM);
   objectShapeDef.friction = 0.1;
   objectShapeDef.restitution = 0.7;
   objectShapeDef.density = 0.05;
   
   // create the body definition
   auto objectBodyDef = new bzBodyDef(bzVec2.zeroVect, 0);
   //objectBodyDef.linearDamping = 1;

   objectBodyDef.position = bzVec2(0, 0);
   objectBodyDef.angle = 0;
   objectBodyDef.isBullet = true;
   objectBodyDef.fixedRotation = true;
   
   // create the body
   auto objectBody = world.createBody(objectBodyDef);
   
   // create the shape
   objectBody.createShape(objectShapeDef);
   objectBody.setMassFromShapes;
   
   
   arc.window.open("edgetest", 800, 600, false);
   arc.input.open;
   
   Point vec2point(bzVec2 v) {
      return Point(v.x, v.y);
   }
   bzVec2 point2vec(Point v) {
      return bzVec2(v.x, v.y);
   }
   
   Point start;
   
   arc.window.clear;
   
   bool running = true;
   while(running) {
      
      // Process time
      processTime;
      
      world.step(1f / 30f, 10, 8);
      
      objectBody.unFreeze;
      objectBody.wakeup;
      
      drawRectangle(vec2point(wallBody.position) * pxPerM, Size(50, 400), Color.White, false);
      drawRectangle(vec2point(objectBody.position - bzVec2(5f / 2f, 5f / 2f)) * pxPerM, Size(5, 5), Color.Red, false);
      
      arc.input.process;

      if(arc.input.keyPressed(ARC_QUIT) || arc.input.keyPressed(ARC_ESCAPE)) running = false;
      if(arc.input.keyPressed(ARC_PRINT)) arc.window.screenshot("screenshot");
      if(arc.input.keyPressed(ARC_PAUSE)) {
         do {
            arc.input.process;
         } while(!arc.input.keyPressed(ARC_PAUSE));
      }
      if(arc.input.mouseButtonPressed(LEFT)) {
         start = arc.input.mousePos;
      } else if(arc.input.mouseButtonReleased(LEFT)) {
         objectBody.xf.position = point2vec(start) / pxPerM;
         Point end = arc.input.mousePos;
         objectBody.applyForce(point2vec((end - start) / pxPerM), objectBody.position);
         start = Point.zeroVect;
      }
      if(start != Point.zeroVect) {
         drawLine(start, arc.input.mousePos, Color.Green);
      }
      
      // switch to next window frame
      arc.window.swap;
      //arc.window.clear;

      // Limit fps
      limitFPS(FRAMERATE);
   }

   // close window when done with it
   scope(exit) {
      arc.font.close;
      arc.input.close;
      arc.window.close;
   }
}

//current time
uint startOfFrameTime = 0;
//previous time
uint prevStartOfFrameTime = 0;
//Frames per second
uint fps_ = 0;
//helpers for fps calculation
const uint FRAMERATE = 30;
uint frames = 0;
uint msPassed = 0;

// Code to keep frame rate constant
/**
   Calculates fps and captures start of frame time.
   Call at the start of the frame loop.
**/
void processTime()
{
   if (startOfFrameTime == 0) {
      startOfFrameTime = SDL_GetTicks();
      prevStartOfFrameTime = startOfFrameTime - 1;
   }

   prevStartOfFrameTime = startOfFrameTime;
   startOfFrameTime = SDL_GetTicks();

   frames++;

   msPassed += (startOfFrameTime - prevStartOfFrameTime);

   if (msPassed > 1000) {
      fps_ = frames;
      frames = 0;
      msPassed = 0;
   }
}

void limitFPS(uint maxFps)
{
   int targetMsPerFrame = 1000 / maxFps;
   uint cTime = SDL_GetTicks();

   int sleepAmount = targetMsPerFrame - (cTime - startOfFrameTime);

   if (sleepAmount <= 0)
      return;

   SDL_Delay(sleepAmount);
}


the screenshot is attached.
boscop wrote:
in my game I have bullets that are small and fast. Of course they have isBullet set but sometimes they still move through other shapes, especially edge shapes


Edge shapes do not handle deep bullet penetrations very well, unless there's been an update the the Box2D trunk that I'm unaware of. See this thread for reference:
http://www.box2d.org/forum/viewtopic.php?f=3&t=1577

Also, I would not recommend using edge shapes to construct convex polygons. Use a regular polygon and there should be no bullet issues.
I tried a port of the above setup in Box2D Flash, and it held up fine. The linked posts were written before b2Distance calculations were done (properly) for edges shapes. I've checked the SVN, and they're there now, so yes, I'm afraid you have missed an update at some point.

Original thread: https://box2d.org/forum/viewtopic.php?t=3127