For your reference, please view the Playgrounds and GIF’s below:
Scenario:
- 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 ):
- Bullets generated in
onBeforeStepObservable
- Player is moved using
setLinearVelocity
https://playground.babylonjs.com/#VIK339#7
Case 2 (Bullets match player’s position ):
- Bullets generated in
registerBeforeRender
- Player is moved using
setLinearVelocity
https://playground.babylonjs.com/#VIK339#8
Note:
// 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!