UNPKG

ggabcd-meshwalk

Version:

MeshWalk.js is a JS library which helps your TPS game development with three.js.

39 lines (32 loc) 1.33 kB
import { THREE, onInstallHandlers } from "../install.js"; import CameraControls from "ggabcd-camera-controls"; onInstallHandlers.push(() => { CameraControls.install({ THREE }); }); export class TPSCameraControls extends CameraControls { constructor(camera, trackObject, domElement) { super(camera, domElement); this.minDistance = 1; this.maxDistance = 300; this.azimuthRotateSpeed = 0.3; // negative value to invert rotation direction this.polarRotateSpeed = -0.2; // negative value to invert rotation direction this.minPolarAngle = 30 * THREE.Math.DEG2RAD; this.maxPolarAngle = 120 * THREE.Math.DEG2RAD; this.draggingDampingFactor = 1; this.mouseButtons.right = CameraControls.ACTION.NONE; this.mouseButtons.middle = CameraControls.ACTION.NONE; this.touches.two = CameraControls.ACTION.TOUCH_DOLLY; this.touches.three = CameraControls.ACTION.TOUCH_DOLLY; this.offset = new THREE.Vector3(0, 1, 0); this.update = (delta) => { const x = trackObject.position.x + this.offset.x; const y = trackObject.position.y + this.offset.y; const z = trackObject.position.z + this.offset.z; this.moveTo(x, y, z, false); super.update(delta); }; } get frontAngle() { return this.azimuthAngle; } }