I'm working on a walkthrough of a three-story apartment. Navigation constraints are done via a navmesh that covers every floor including the staircase.
I want to provide a shortcut where the user can click on a button and jump to the respective floor. So far the changing of position works but as soon as the player starts walking, they are pulled back to the same Y-position that they’ve been at before clicking the button (x- and z-position change works). For example, the jump from the first to the third floor works, but as soon as the player starts walking, they're back on the first floor again.
The position.set values aren't chosen randomly – I checked the position of the camRig on the third floor in the loading inspector and used these values, so I'm not sure why this doesn't work. Is there any way to avoid this issue?
Edit: I made a quick example that reproduces the problem: https://glitch.com/~fearless-resolution
This is my code:
<a-entity id="camRig"
movement-controls="speed: 0.3;
constrainToNavMesh: true"
position="-12.5 0 -2"
rotation="0 270 0">
<a-entity id="cam" camera
look-controls="pointerLockEnabled: true;"
position="0 2.4 0"></a-entity>
</a-entity>
<a-entity id="navmesh" gltf-model="#collider" nav-mesh position="0 0 0" scale="1.6 1.6 1.6" visible=„false“></a-entity>
<a-entity id="house" gltf-model="#apartment" position="0 0 0" scale="0.016 0.016 0.016"></a-entity>
document.querySelector("#changeFloorButton").addEventListener('click', function() {
document.querySelector("#camRig").object3D.position.set(-1, 4, 2);
});
When 'teleporting' around, you need to reset the navigation data:
// provided player has the camRig
player.components['movement-controls'].updateNavLocation()
otherwise the calculations keeping you within the navmesh will teleport you back if you move too soon (seems so in the primitives example).