From 629a4ad7ebb7b07cf23bab4bfd0e9f550b5a34cb Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Tue, 6 Jul 2021 08:19:31 +1000 Subject: [PATCH] Enable fixed physics update to prevent issues with low frame rates --- src/components/dice/DiceInteraction.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/dice/DiceInteraction.js b/src/components/dice/DiceInteraction.js index f5d225b..26c1090 100644 --- a/src/components/dice/DiceInteraction.js +++ b/src/components/dice/DiceInteraction.js @@ -40,7 +40,10 @@ function DiceInteraction({ onSceneMount, onPointerDown, onPointerUp }) { const scene = new Scene(engine); scene.clearColor = new Color4(0, 0, 0, 0); // Enable physics - scene.enablePhysics(new Vector3(0, -98, 0), new AmmoJSPlugin(true, AMMO)); + scene.enablePhysics( + new Vector3(0, -98, 0), + new AmmoJSPlugin(false, AMMO) + ); let camera = new TargetCamera("camera", new Vector3(0, 33.5, 0), scene); camera.fov = 0.65; @@ -67,13 +70,14 @@ function DiceInteraction({ onSceneMount, onPointerDown, onPointerUp }) { const delta = newPosition.subtract(currentPosition); selectedMesh.setAbsolutePosition(newPosition); const velocity = delta.scale(1000 / scene.deltaTime); - selectedMeshVelocityWindowRef.current = selectedMeshVelocityWindowRef.current.slice( - Math.max( - selectedMeshVelocityWindowRef.current.length - - selectedMeshVelocityWindowSize, - 0 - ) - ); + selectedMeshVelocityWindowRef.current = + selectedMeshVelocityWindowRef.current.slice( + Math.max( + selectedMeshVelocityWindowRef.current.length - + selectedMeshVelocityWindowSize, + 0 + ) + ); selectedMeshVelocityWindowRef.current.push(velocity); } });