diff --git a/constants.js b/constants.js index 65061f0f40..b347b63716 100644 --- a/constants.js +++ b/constants.js @@ -92,6 +92,7 @@ export const activateMaxTime = 750; export const useMaxTime = 750; export const aimMaxTime = 1000; export const throwReleaseTime = 220; +export const throwAnimationDuration = 1.4166666269302368; export const minFov = 60; export const maxFov = 120; export const midFov = 90; diff --git a/game.js b/game.js index 9f141e2284..5297257915 100644 --- a/game.js +++ b/game.js @@ -14,7 +14,7 @@ import {world} from './world.js'; import {buildMaterial, highlightMaterial, selectMaterial, hoverMaterial, hoverEquipmentMaterial} from './shaders.js'; import {getRenderer, sceneLowPriority, camera} from './renderer.js'; import {downloadFile, snapPosition, getDropUrl, handleDropJsonItem} from './util.js'; -import {maxGrabDistance, throwReleaseTime, storageHost, minFov, maxFov} from './constants.js'; +import {maxGrabDistance, throwReleaseTime, storageHost, minFov, maxFov, throwAnimationDuration} from './constants.js'; import metaversefileApi from './metaversefile-api.js'; import * as metaverseModules from './metaverse-modules.js'; import loadoutManager from './loadout-manager.js'; @@ -42,6 +42,8 @@ const localMatrix3 = new THREE.Matrix4(); // const localBox = new THREE.Box3(); const localRay = new THREE.Ray(); +let isMouseUp = false; + // const zeroVector = new THREE.Vector3(0, 0, 0); // const oneVector = new THREE.Vector3(1, 1, 1); // const cubicBezier = easing(0, 1, 0, 1); @@ -433,7 +435,7 @@ const _mousedown = () => { _startUse(); }; const _mouseup = () => { - _endUse(); + isMouseUp = true; }; const _grab = object => { @@ -998,6 +1000,23 @@ const _gameUpdate = (timestamp, timeDiff) => { !_getGrabbedObject(0); crosshairEl.style.visibility = visible ? null : 'hidden'; } + + const _updateUse = () => { + const useAction = localPlayer.getAction('use'); + if (useAction) { + if (useAction.animation === 'pickUpThrow') { + const useTime = localPlayer.actionInterpolants.use.get(); + if (useTime / 1000 >= throwAnimationDuration) { + _endUse(); + } + } else if (isMouseUp) { + _endUse(); + } + + } + isMouseUp = false; + }; + _updateUse(); }; const _pushAppUpdates = () => { world.appManager.pushAppUpdates();