Three.js VR Teleportation (Parabolic Arc Locomotion)
Comfortable VR locomotion in Three.js with a parabolic teleport arc ray-tested segment by segment, target validation by surface slope and blocked areas, blink fade, snap turning and rig-relative movement, using XR controllers or the mouse on desktop.
Key topics: vr teleportation, teleport locomotion, webxr controllers, parabolic arc, vr comfort, three.js vr
Game Over
What this code does
- Arc: a projectile launched from the controller (v₀ along its forward axis, gravity −9.8 m/s²) is stepped every 30 ms, each segment ray-tested against the world.
- Validation: the hit must be walkable, flatter than the maximum slope (acos(normal.y)) and not water or an obstacle; the arc and reticle turn red otherwise.
- Rig Movement: in VR the headset owns the camera, so the parent rig moves by target − head offset, landing your head (not the play-space centre) on the reticle.
- Comfort: a quick fade to black hides the jump and avoids vection; snap turns rotate the rig in fixed steps.
- Input: hold the trigger to aim and release to teleport (selectstart/selectend); on desktop the mouse aims and click teleports, with Q/E to snap turn.
- Controls: arc launch speed, maximum slope, snap angle, blink fade and auto demo.
Related Demos
Continue Learning
JavaScript Implementation
// Teleport arc: step a projectile from the controller and ray-test each segment
const v = controllerForward.multiplyScalar(8), p = controllerPosition.clone()
for (let i = 0; i < 40; i++) {
const next = p.clone().addScaledVector(v, 0.03); v.y -= 9.8 * 0.03
raycaster.set(p, next.clone().sub(p).normalize()); raycaster.far = p.distanceTo(next)
const hit = raycaster.intersectObjects(floorAndObstacles)[0]
if (hit) { target = hit; break }
p.copy(next)
}
// Valid if walkable and flat: acos(normal.y) < maxSlope. On release move the *rig*, keeping the head offset:
rig.position.set(hit.point.x - headOffset.x, hit.point.y, hit.point.z - headOffset.z)