Teleport on screen click
This commit is contained in:
parent
26b92e6411
commit
8ca1c44af1
2
TODO
2
TODO
|
@ -1,4 +1,4 @@
|
|||
portals to other scenes
|
||||
✓ collision events
|
||||
✓ touch events/interactions
|
||||
motion with xr without a controller
|
||||
✓ motion with xr without a controller
|
||||
|
|
|
@ -104,11 +104,30 @@ export async function startEngine(
|
|||
camera.applyGravity = true;
|
||||
camera.ellipsoid = new Vector3(0.25, 0.8, 0.25);
|
||||
|
||||
const teleport = () => {
|
||||
const ray = xr.baseExperience.camera.getForwardRay();
|
||||
const meshes = floorMeshes();
|
||||
const hit = scene.pickWithRay(ray, m => meshes.indexOf(m as any) !== -1);
|
||||
if (hit !== null) {
|
||||
if (meshes.indexOf(hit.pickedMesh as any) !== -1) {
|
||||
if (hit.pickedPoint !== null) {
|
||||
xr.baseExperience.camera.position =
|
||||
hit.pickedPoint.add(new Vector3(0, 1.6, 0));
|
||||
xr.baseExperience.camera.rotation = Vector3.Zero();
|
||||
if (leanBase !== null) {
|
||||
leanBase.position = xr.baseExperience.camera.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const enableVR = () => {
|
||||
if (xrAvailable) {
|
||||
xr.baseExperience.enterXRAsync('immersive-vr', 'local').then(() => {
|
||||
xr.baseExperience.camera.position = initialPos;
|
||||
xr.baseExperience.camera.rotation = initialRotation;
|
||||
xr.baseExperience.sessionManager.session.onselect = teleport;
|
||||
});
|
||||
} else {
|
||||
canvas.requestPointerLock?.();
|
||||
|
@ -143,21 +162,7 @@ export async function startEngine(
|
|||
}
|
||||
|
||||
if (sm && latch(gp, 0)) {
|
||||
const ray = xr.baseExperience.camera.getForwardRay();
|
||||
const meshes = floorMeshes();
|
||||
const hit = scene.pickWithRay(ray, m => meshes.indexOf(m as any) !== -1);
|
||||
if (hit !== null) {
|
||||
if (meshes.indexOf(hit.pickedMesh as any) !== -1) {
|
||||
if (hit.pickedPoint !== null) {
|
||||
xr.baseExperience.camera.position =
|
||||
hit.pickedPoint.add(new Vector3(0, 1.6, 0));
|
||||
xr.baseExperience.camera.rotation = Vector3.Zero();
|
||||
if (leanBase !== null) {
|
||||
leanBase.position = xr.baseExperience.camera.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
teleport();
|
||||
}
|
||||
if (latch(gp, 2)) {
|
||||
location.reload();
|
||||
|
|
Loading…
Reference in New Issue