Added reset to dice physics when rerolling

This commit is contained in:
Mitchell McCaffrey 2020-05-25 20:52:11 +10:00
parent 70f68a9093
commit 3be729d4a0
2 changed files with 5 additions and 2 deletions

View File

@ -65,10 +65,10 @@ function DiceScene({ onSceneMount, onPointerDown, onPointerUp }) {
const pickInfo = scene.pick(scene.pointerX, scene.pointerY);
if (pickInfo.hit && pickInfo.pickedMesh.id !== "tray") {
pickInfo.pickedMesh.physicsImpostor.setLinearVelocity(
new BABYLON.Vector3(0, 0, 0)
BABYLON.Vector3.Zero()
);
pickInfo.pickedMesh.physicsImpostor.setAngularVelocity(
new BABYLON.Vector3(0, 0, 0)
BABYLON.Vector3.Zero()
);
selectedMeshRef.current = pickInfo.pickedMesh;
}

View File

@ -75,6 +75,9 @@ class Dice {
}
static roll(instance) {
instance.physicsImpostor.setLinearVelocity(BABYLON.Vector3.Zero());
instance.physicsImpostor.setAngularVelocity(BABYLON.Vector3.Zero());
const trayOffsetHeight = diceTraySize.height / 2 - 0.5;
const position = new BABYLON.Vector3(
((Math.random() * 2 - 1) * diceTraySize.width) / 2,