Matter Physics in Phaser v3.60

I don’t really use Matter and I don’t have a 144Hz monitor :smiley: but here are my impressions.

By default Matter makes a variable-sized step using the minimum delta from the last 60 frames, clamped within 16–33ms:

These values are fine for browser animation rates of 30–60fps but above or below that Matter will be running ahead or behind the game step rate.

You could limit Phaser’s frame rate to 60fps also:

new Phaser.Game({
  fps: {
    forceSetTimeOut: true,
    target: 60
  },
  physics: {
    default: 'matter',
    matter: {
      runner: {
        fps: 60
      }
    }
  }
});

Or you could have Matter use Phaser’s delta:

new Phaser.Game({
  physics: {
    default: 'matter',
    matter: {
      getDelta: function () {
        return this.scene.game.loop.delta;
      },
      runner: {
        // `isFixed` means use `getDelta()`
        isFixed: true
      }
    }
  }
});

You probably don’t want to enable matter.runner.isFixed by itself, because that will make Matter run a fixed-size step (60Hz) no matter what Phaser’s delta is. Likewise with set60Hz() and set30Hz().

A good solution might be to turn off Matter’s autoUpdate and step through the game loop delta manually at a fixed rate:

:warning: Beware that applyForce() and thrust() are still timestep dependent.

Here’s a small Scene Plugin that runs a fixed-step Matter loop: