0.2.0 • Published 6 years ago

three-firstperson-vr-controls v0.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

THREE.FirstPersonVRControls

npm

First-person keyboard controls for VR based on three.js with look-based movement and "comfort mode" snap turning.

Controls

  • WASD or for forward/backward movement and strafing (if enabled).
  • Shift to boost movement speed temporarily.
  • QE for snap turns.
  • RF for vertical movement (if enabled).
  • Forward/backward movement is always in the direction that you're looking.

Usage

$ npm install three-firstperson-vr-controls
...  

// Create a rig and add the camera to it. 
// FirstPersonVRControls will move the rig, instead of moving the camera directly. 
// If you don't provide a rig, FirstPersonVRControls will create one for you.
const rig = new THREE.Object3D();
rig.add(camera);
scene.add(rig);

const fpVrControls = new THREE.FirstPersonVRControls(camera, scene, rig);
// Optionally enable vertical movement.
fpVrControls.verticalMovement = true;
// You can also enable strafing, set movementSpeed, snapAngle and boostFactor.
fpVrControls.strafing = true;
...
const clock = new THREE.Clock();
function animate () {
  ...
  // FirstPersonControls requires a time delta.
  fpVrControls.update(clock.getDelta());
  renderer.render(scene, camera);
}
renderer.animate(animate);

Demo

http://brian.peiris.io/three-firstperson-vr-controls/demo/browser-demo.html

Animated demo of the controls in action

Credits

Based on code from THREE.FirstPersonControls and its contributors.