UNPKG

@threejs-addons/threejs-addons

Version:

free & opensource threejs addons to boost productivity

21 lines (20 loc) 741 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.calculateVelocity = void 0; const Vector3_1 = require("three/src/math/Vector3"); /** * @description calculate velocity based on direction vector * @param direction * @returns velocity */ const calculateVelocity = ({ direction, delta, SPEED_UP_CONSTANT, speedFactor }) => { let VAL_ENUM = [1, -1]; let velocity = new Vector3_1.Vector3(0, 0, 0); for (const [key, index] of Object.keys(direction)) { if (VAL_ENUM.includes(direction[key])) { velocity[key] -= direction[key] * SPEED_UP_CONSTANT * delta * speedFactor; } } return velocity; }; exports.calculateVelocity = calculateVelocity;