An open API service indexing awesome lists of open source software.

https://github.com/brianpeiris/three-firstperson-vr-controls

First-person controls for VR based on three.js
https://github.com/brianpeiris/three-firstperson-vr-controls

Last synced: about 1 year ago
JSON representation

First-person controls for VR based on three.js

Awesome Lists containing this project

README

          

# THREE.FirstPersonVRControls

[![npm](https://img.shields.io/npm/v/three-firstperson-vr-controls.svg)](https://www.npmjs.com/package/three-firstperson-vr-controls)

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

```javascript
...

// 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](demo/demo.gif)

## Credits

Based on code from [THREE.FirstPersonControls](https://github.com/mrdoob/three.js/blob/master/examples/js/controls/FirstPersonControls.js) and its contributors.