UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

77 lines (76 loc) 2.04 kB
"use strict"; import { findPhysicsPlayer } from "../../core/physics/player/PhysicsPlayer"; import { ObjectNamedFunction1 } from "./_Base"; function _createInputData() { return { forward: false, backward: false, left: false, right: false, run: false, jump: false }; } function _createComputeData() { return { speed: 1, runAllowed: false, runSpeedMult: 2, jumpAllowed: false, jumpStrength: 2, resetIfBelowThreshold: false, resetThreshold: -5 }; } const _elementByObject3D = /* @__PURE__ */ new WeakMap(); function _findOrCreateElement(object3D) { let element = _elementByObject3D.get(object3D); if (element) { return element; } const player = findPhysicsPlayer(object3D); if (!player) { return; } element = { player, inputData: _createInputData(), computeData: _createComputeData() }; _elementByObject3D.set(object3D, element); return element; } export class playerPhysicsUpdate extends ObjectNamedFunction1 { static type() { return "playerPhysicsUpdate"; } func(object3D, options) { const { speed, runAllowed, runSpeedMult, jumpAllowed, jumpStrength, resetIfBelowThreshold, resetThreshold, left, right, backward, forward, run, jump } = options; const element = _findOrCreateElement(object3D); if (!element) { return; } const { player, inputData, computeData } = element; computeData.speed = speed; computeData.runAllowed = runAllowed; computeData.runSpeedMult = runSpeedMult; computeData.jumpAllowed = jumpAllowed; computeData.jumpStrength = jumpStrength; computeData.resetIfBelowThreshold = resetIfBelowThreshold; computeData.resetThreshold = resetThreshold; inputData.left = left; inputData.right = right; inputData.backward = backward; inputData.forward = forward; inputData.run = run; inputData.jump = jump; player.update(computeData, inputData, this.scene.timeController.delta()); } }