Search code examples
box2dphysicsgame-physicsbox2dweb

Execute code at every step in box2d


What would it be the way to execute code in each step (solve) of box2d instead of once per frame.


Solution

  • Is this what you meant?

    var box2DListener = Box2D.Dynamics.b2ContactListener;
    var ContactListener = new box2DListener;
    ContactListener.PreSolve = function(contact, oldManifold) {
      // some code to be executed before each solve
    }
    ContactListener.PostSolve = function(contact, impulse) { 
      // some code to be executed after each solve
    }
    

    It was also covered in Box2dweb - Collision Contact Point thread

    You can find some good examples in Seth Ladd's Blog and TheNightOwl's Blog.