Skip to content

Commit

Permalink
Merge pull request webaverse#3082 from webaverse/Vis/PickUpTreePr
Browse files Browse the repository at this point in the history
Pick up tree animation: Add one click logic.
  • Loading branch information
Avaer Kazmer authored May 30, 2022
2 parents fcbd456 + 583528f commit d0836fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 21 additions & 2 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -433,7 +435,7 @@ const _mousedown = () => {
_startUse();
};
const _mouseup = () => {
_endUse();
isMouseUp = true;
};

const _grab = object => {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit d0836fd

Please sign in to comment.