How can I execute code every physics step?

I’m trying to have force that is constantly applied to an object, rather than a one-off impulse. Right now I’m calling applyForce() from inside the render loop. The problem is, this causes the force to be weaker or stronger depending on your framerate. As far as I know, the physics engine updates at a fixed rate independent of your framerate, but I can’t find a way to hook into that update loop and run my own code at the same rate (like you can with runRenderLoop). Basically, is there a physics version of runRenderLoop?

By the way, I’m currently using the cannon.js plugin, but I’m not opposed to switching to one of the other ones if there’s a good reason to.


1 Like

You would need to use a Physics Imposter and register a physics update handler.


      console.log("Run custom Code Here");


That’s perfect, thanks!