Three.js VR Locomotion & Comfort (Vignette, Snap Turn)
Comfortable smooth locomotion for VR in Three.js, with head- or body-directed movement, snap or smooth turning, ramped acceleration and a dynamic comfort vignette that narrows the field of view with linear and angular speed, working with thumbsticks or the keyboard.
Key topics: vr locomotion, comfort vignette, snap turn, smooth locomotion, motion sickness, webxr
Game Over
What this code does
- Rig Movement: the XR camera's pose belongs to the headset, so locomotion moves and rotates a parent rig and never the camera itself.
- Direction: head-directed movement follows where you look; body-directed follows the rig's yaw, which feels better for many people.
- Turning: snap turns (30/45/90°) with a cooldown and a brief vignette flash avoid continuous rotation, the strongest vection trigger; smooth turning is optional.
- Acceleration Ramp: velocity eases toward the target, because sudden accelerations cause discomfort.
- Vignette: a camera-attached quad darkens the periphery, its radius shrinking with speed and angular velocity so optic flow is reduced.
- Controls: locomotion mode, turning, speed, vignette and strength, and auto demo; WASD or the left stick moves, Q/E or the right stick turns.
Related Demos
Continue Learning
JavaScript Implementation
// Smooth locomotion with a comfort vignette
const dir = new THREE.Vector3(stickX, 0, -stickY).applyAxisAngle(up, headYaw).multiplyScalar(speed)
velocity.lerp(dir, 1 - Math.exp(-dt * 8)) // ramp: avoid sudden acceleration
rig.position.addScaledVector(velocity, dt) // move the rig, never the XR camera
if (Math.abs(turnStick) > 0.6 && cooldown <= 0) { rig.rotation.y += Math.sign(turnStick) * THREE.MathUtils.degToRad(30); cooldown = 0.35 }
vignette.uniforms.uRadius.value = THREE.MathUtils.lerp(1.6, 0.6, Math.min(1, velocity.length() / 3 + Math.abs(angularVelocity)))
// fragment: alpha = smoothstep(radius, radius + soft, length(screenPos)) → black ring narrows the FOV while moving