UNPKG

@needle-tools/engine

Version:

Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in

36 lines (28 loc) 1.14 kB
import { FlyControls as ThreeFlyControls } from "three/examples/jsm/controls/FlyControls.js"; import { Camera } from "./Camera.js"; import { Behaviour, GameObject } from "./Component.js"; /** * @deprecated The FlyControls component is deprecated and will be removed in the future. */ export class FlyControls extends Behaviour { private _controls: ThreeFlyControls | null = null; onEnable(): void { const cam = GameObject.getComponent(this.gameObject, Camera)?.threeCamera; if (!cam) { console.warn("FlyControls: Requires a Camera component on the same object as this component."); return; } this._controls = new ThreeFlyControls(cam, this.context.renderer.domElement); this._controls.rollSpeed = .5; this._controls.movementSpeed = 3; this._controls.dragToLook = true; } onDisable(): void { this._controls?.dispose(); this._controls = null; } update(): void { if (this._controls) this._controls.update(this.context.time.deltaTime); } }