Skip to content

Commit 6eb9c51

Browse files
authored
Merge pull request #183 from dli7319/controllers
Fix errors when `options.controllers.enabled = false;`
2 parents 3e5b312 + b39ec1c commit 6eb9c51

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/input/MouseController.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class MouseController
4040
forwardVector = new THREE.Vector3(0, 0, -1);
4141

4242
/** A reference to the main scene camera. */
43-
camera!: THREE.Camera;
43+
camera?: THREE.Camera;
4444

4545
constructor() {
4646
super();
@@ -63,7 +63,7 @@ export class MouseController
6363
if (!this.userData.connected) {
6464
return;
6565
}
66-
this.position.copy(this.camera.position);
66+
this.position.copy(this.camera!.position);
6767
}
6868

6969
/**
@@ -73,6 +73,9 @@ export class MouseController
7373
* @param event - The mouse event containing clientX and clientY coordinates.
7474
*/
7575
updateMousePositionFromEvent(event: MouseEvent) {
76+
if (this.camera === undefined) {
77+
return;
78+
}
7679
// The controller's origin point is always the camera's position.
7780
this.position.copy(this.camera.position);
7881

src/simulator/controlModes/SimulatorControlMode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export class SimulatorControlMode {
8181

8282
updateControllerPositions() {
8383
this.camera.updateMatrixWorld();
84-
for (let i = 0; i < 2; i++) {
84+
for (let i = 0; i < 2 && i < this.input.controllers.length; i++) {
8585
const controller = this.input.controllers[i];
8686
controller.position
8787
.copy(this.simulatorControllerState.localControllerPositions[i])

0 commit comments

Comments
 (0)