Tweak xrStepOrTouch
This commit is contained in:
parent
9bdc37bda1
commit
f0f6f73c1f
|
@ -8,6 +8,7 @@ import {
|
|||
KeyboardEventTypes,
|
||||
PerformanceMonitor,
|
||||
Quaternion,
|
||||
Ray,
|
||||
Scene,
|
||||
Vector3,
|
||||
WebXRCamera,
|
||||
|
@ -290,11 +291,16 @@ export class RunningEngine {
|
|||
this.xrTeleportTimer = setTimeout(() => {
|
||||
this.clearTeleportTimer();
|
||||
this.xrTeleport();
|
||||
}, 333);
|
||||
}, 1000);
|
||||
}
|
||||
if (actionButton.wasReleased && this.xrTeleportTimer !== null) {
|
||||
this.clearTeleportTimer();
|
||||
this.xrStepOrTouch();
|
||||
let a = 0;
|
||||
let a = Quaternion.Identity();
|
||||
if (state.b(13 /* dPadDown */).isDown) a = 1;
|
||||
if (state.b(14 /* dPadLeft */).isDown) a = -0.5;
|
||||
if (state.b(15 /* dPadRight */).isDown) a = 0.5;
|
||||
this.xrStepOrTouch(Quaternion.RotationYawPitchRoll(a * Math.PI, 0, 0));
|
||||
}
|
||||
|
||||
const shareButton = state.b(8 /* share */);
|
||||
|
@ -369,14 +375,15 @@ export class RunningEngine {
|
|||
}
|
||||
}
|
||||
|
||||
xrStepOrTouch() {
|
||||
xrStepOrTouch(a: Quaternion) {
|
||||
if (!this.inXR) return;
|
||||
|
||||
const ray = this.xrCamera!.getForwardRay();
|
||||
ray.direction.rotateByQuaternionToRef(a, ray.direction);
|
||||
const hit = this.scene.pickWithRay(ray);
|
||||
|
||||
if (hit !== null
|
||||
&& hit.distance <= 1
|
||||
&& hit.distance <= 1.5
|
||||
&& this.interactivity.touchableMeshes().indexOf(hit.pickedMesh as any) !== -1)
|
||||
{
|
||||
this.camera.onCollide?.(hit.pickedMesh!);
|
||||
|
@ -385,7 +392,20 @@ export class RunningEngine {
|
|||
|
||||
const stepDistance =
|
||||
hit && hit.hit && hit.distance <= 1 ? hit.distance * 0.5 : 1;
|
||||
if (stepDistance < 0.5) return;
|
||||
|
||||
const pos = this.xrCamera!.position.add(ray.direction.normalizeToNew().scale(stepDistance));
|
||||
|
||||
const downRay = new Ray(pos, new Vector3(0, -1, 0));
|
||||
const downHit = this.scene.pickWithRay(downRay);
|
||||
|
||||
if (downHit !== null
|
||||
&& downHit.distance <= 1.6
|
||||
&& this.interactivity.floorMeshes().indexOf(downHit.pickedMesh as any) !== -1)
|
||||
{
|
||||
pos.addInPlace(new Vector3(0, 1.6 - downHit.distance, 0));
|
||||
}
|
||||
|
||||
this.xrCamera!.position = pos;
|
||||
if (this.leanBase !== null) this.leanBase.position = pos;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue