|
@@ -19,6 +19,14 @@ export class WebXRControllerTeleportation {
|
|
private _tmpVector = new Vector3();
|
|
private _tmpVector = new Vector3();
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * when set to true (default) teleportation will wait for thumbstick changes.
|
|
|
|
+ * When set to false teleportation will be disabled.
|
|
|
|
+ *
|
|
|
|
+ * If set to false while teleporting results can be unexpected.
|
|
|
|
+ */
|
|
|
|
+ public enabled: boolean = true;
|
|
|
|
+
|
|
|
|
+ /**
|
|
* Creates a WebXRControllerTeleportation
|
|
* Creates a WebXRControllerTeleportation
|
|
* @param input input manager to add teleportation to
|
|
* @param input input manager to add teleportation to
|
|
* @param floorMeshes floormeshes which can be teleported to
|
|
* @param floorMeshes floormeshes which can be teleported to
|
|
@@ -81,7 +89,10 @@ export class WebXRControllerTeleportation {
|
|
|
|
|
|
// Handle user input on every frame
|
|
// Handle user input on every frame
|
|
let renderObserver = scene.onBeforeRenderObservable.add(() => {
|
|
let renderObserver = scene.onBeforeRenderObservable.add(() => {
|
|
- // Move the teleportationTarget to where the user is targetting to teleport to
|
|
|
|
|
|
+ if (!this.enabled) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ // Move the teleportationTarget to where the user is targeting to teleport to
|
|
if (forwardReadyToTeleport) {
|
|
if (forwardReadyToTeleport) {
|
|
c.getWorldPointerRayToRef(this._tmpRay);
|
|
c.getWorldPointerRayToRef(this._tmpRay);
|
|
let pick = scene.pickWithRay(this._tmpRay, (o) => {
|
|
let pick = scene.pickWithRay(this._tmpRay, (o) => {
|
|
@@ -100,13 +111,13 @@ export class WebXRControllerTeleportation {
|
|
}
|
|
}
|
|
|
|
|
|
if (c.inputSource.gamepad) {
|
|
if (c.inputSource.gamepad) {
|
|
- if (c.inputSource.gamepad.axes[1] !== undefined) {
|
|
|
|
|
|
+ if (c.inputSource.gamepad.axes[3] !== undefined) {
|
|
// Forward teleportation
|
|
// Forward teleportation
|
|
- if (c.inputSource.gamepad.axes[1] < -0.7) {
|
|
|
|
|
|
+ if (c.inputSource.gamepad.axes[3] < -0.7) {
|
|
forwardReadyToTeleport = true;
|
|
forwardReadyToTeleport = true;
|
|
} else {
|
|
} else {
|
|
if (forwardReadyToTeleport) {
|
|
if (forwardReadyToTeleport) {
|
|
- // Teleport the users feet to where they targetted
|
|
|
|
|
|
+ // Teleport the users feet to where they targeted
|
|
this._tmpVector.copyFrom(teleportationTarget.position);
|
|
this._tmpVector.copyFrom(teleportationTarget.position);
|
|
this._tmpVector.y += input.baseExperience.camera.position.y;
|
|
this._tmpVector.y += input.baseExperience.camera.position.y;
|
|
input.baseExperience.setPositionOfCameraUsingContainer(this._tmpVector);
|
|
input.baseExperience.setPositionOfCameraUsingContainer(this._tmpVector);
|
|
@@ -115,7 +126,7 @@ export class WebXRControllerTeleportation {
|
|
}
|
|
}
|
|
|
|
|
|
// Backward teleportation
|
|
// Backward teleportation
|
|
- if (c.inputSource.gamepad.axes[1] > 0.7) {
|
|
|
|
|
|
+ if (c.inputSource.gamepad.axes[3] > 0.7) {
|
|
backwardReadyToTeleport = true;
|
|
backwardReadyToTeleport = true;
|
|
} else {
|
|
} else {
|
|
if (backwardReadyToTeleport) {
|
|
if (backwardReadyToTeleport) {
|
|
@@ -135,7 +146,7 @@ export class WebXRControllerTeleportation {
|
|
});
|
|
});
|
|
|
|
|
|
if (pick && pick.pickedPoint) {
|
|
if (pick && pick.pickedPoint) {
|
|
- // Teleport the users feet to where they targetted
|
|
|
|
|
|
+ // Teleport the users feet to where they targeted
|
|
this._tmpVector.copyFrom(pick.pickedPoint);
|
|
this._tmpVector.copyFrom(pick.pickedPoint);
|
|
this._tmpVector.y += input.baseExperience.camera.position.y;
|
|
this._tmpVector.y += input.baseExperience.camera.position.y;
|
|
input.baseExperience.setPositionOfCameraUsingContainer(this._tmpVector);
|
|
input.baseExperience.setPositionOfCameraUsingContainer(this._tmpVector);
|
|
@@ -145,8 +156,8 @@ export class WebXRControllerTeleportation {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (c.inputSource.gamepad.axes[0] !== undefined) {
|
|
|
|
- if (c.inputSource.gamepad.axes[0] < -0.7) {
|
|
|
|
|
|
+ if (c.inputSource.gamepad.axes[2] !== undefined) {
|
|
|
|
+ if (c.inputSource.gamepad.axes[2] < -0.7) {
|
|
leftReadyToTeleport = true;
|
|
leftReadyToTeleport = true;
|
|
} else {
|
|
} else {
|
|
if (leftReadyToTeleport) {
|
|
if (leftReadyToTeleport) {
|
|
@@ -154,7 +165,7 @@ export class WebXRControllerTeleportation {
|
|
}
|
|
}
|
|
leftReadyToTeleport = false;
|
|
leftReadyToTeleport = false;
|
|
}
|
|
}
|
|
- if (c.inputSource.gamepad.axes[0] > 0.7) {
|
|
|
|
|
|
+ if (c.inputSource.gamepad.axes[2] > 0.7) {
|
|
rightReadyToTeleport = true;
|
|
rightReadyToTeleport = true;
|
|
} else {
|
|
} else {
|
|
if (rightReadyToTeleport) {
|
|
if (rightReadyToTeleport) {
|