-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteract.ts
More file actions
30 lines (23 loc) · 905 Bytes
/
interact.ts
File metadata and controls
30 lines (23 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { FirstPersonControls } from "three/addons/controls/FirstPersonControls";
export class InteractionManager {
private isMovementToggleAllowed: boolean = false;
constructor(private controls: FirstPersonControls) {
this.controls.enabled = false;
document.addEventListener("keypress", (event) => {
if (!this.isMovementToggleAllowed) return;
if (event.code == "Space") {
this.controls.enabled = !this.controls.enabled;
console.log("Toggling movement enabled state to: ", this.controls.enabled);
}
});
}
public update(delta: number): void {
this.controls.update(delta);
}
public setAllowToggle(isAllowed: boolean) {
this.isMovementToggleAllowed = isAllowed;
}
public setMovementEnabled(isEnabled: boolean) {
this.controls.enabled = isEnabled;
}
}