Teleport on screen click

This commit is contained in:
Tony Garnock-Jones 2023-01-06 16:02:36 +01:00
parent 26b92e6411
commit 8ca1c44af1
2 changed files with 21 additions and 16 deletions

2
TODO
View File

@ -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

View File

@ -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();