computeWorldMatrix gives delayed positions when using Physics in onBeforeStepObservable

For your reference, please view the Playgrounds and GIF’s below:


  • Orange player is moving left and right
  • Red gun muzzle is a child of the player
  • Cyan bullets are generated at the muzzle’s position

Case 1 (Bullets delayed behind player :cry:):

  • Bullets generated in onBeforeStepObservable
  • Player is moved using setLinearVelocity

Case 2 (Bullets match player’s position :smile:):

  • Bullets generated in registerBeforeRender
  • Player is moved using setLinearVelocity


// Movement Method #1
player.position.z += sign * 1e-1;

// Movement Method #2
// const velocity = new BABYLON.Vector3(0, 0, sign * 5);
// player.physicsImpostor.setLinearVelocity(velocity);

Please note that when using Movement Method #1 instead of #2, results are good like those shown in Case 2 regardless of using registerBeforeRender or onBeforeStepObservable

Is it possible to have the results from Case 2 when using setLinearVelocity in onBeforeStepObservable in Case 1?

Please note that this bug exists for Cannon, Ammo, and Oimo

Thank you for your time and help! :smiley:

Pinging @RaananW

1 Like

Potential workaround: The cyan mesh correctly follows the orange mesh using onAfterStepObservable:

Still unsure why this isn’t the case for onBeforeStepObservable

I believe this is more an issue with the getAbosultePosition call and less the physics engine, but I am not sure. I can find time later this week and see what’s up here :slight_smile:

1 Like

Thank you so much, @RaananW :smile: