Bullet lifespan (Phaser 3)

Since Phaser v3.50.0 you can use the Arcade Physics delta in its WORLD_STEP event callback. We can use the delta to implement precise bullet lifespans in physics time. Bullet lifespans are slightly simpler than bullet ranges since no distances need to be calculated.

function fireBullet (bullet)
{
  // …
  bullet.setState(BULLET_LIFESPAN);
}

function updateBullet(bullet, delta) {
  bullet.state -= delta;

  if (bullet.state <= 0) {
    bullet.disableBody(true, true);
  }
}

1 Like