Appearance
Controls â
controls is a global singleton which provides an interface for VR, desktop and mobile inputs. These are the default controls and provide your standard third/first person controls for mobile/desktop and VR locomotion. This also stores controller state e.g. mouse interactions of VR hand/controller interactions and state.
Examples: â
js
// set object's local postion to the left controller position (world space)
this.update = () => {
this.position.copy(controls.left.position);
};
// Vibrate the controller when it clicks an object
this.click = (evt) => {
// Pulse at max intensity, for 20ms
// evt.hand is 'left' or 'right'
controls[evt.hand].pulse(1.0, 20);
};
this.update = () => {
// If using hand tracking
if (controls.right.inputSource == 2) {
this.position.copy(controls.right.hand["index-finger-tip"].position);
}
};
// Set nested object's rotation/quaternion to controller quaternion
this.update = () => {
// get inverse of parent quaternion
const quaternion = new THREE.Quaternion();
this.parent.getWorldQuaternion(quaternion);
quaternion.invert();
// copy it so that objects world rotation is 0, 0, 0
this.quaternion.copy(quaternion);
// then multiply / set from world controller rotation
this.quaternion.multiply(controls.left.quaternion);
};
// Change walking speed on desktop, and locomotion speed in VR
controls.speed = 3;
// Set camera to first person
controls.zoom = 0;
// Set camera to third person
controls.zoom = 2.5;controls.zoom : Number â
Controls how far away the camera is from the player on mobile and desktop. Setting controls.zoom = 0 is first person and controls.zoom > 0.5 is third person, (3 is the default).
controls.yShift : Number â
How far to move the camera above player eye height. This scales is multiplied by controls.zoom:
js
camera.position.y += controls.zoom * controls.yShift;This is useful if you want to move the camera higher so the player's head doesn't overlap with the cursor. The default is 0.1
controls.speed : Number â
Movement speed
controls.intersections : Array â
An array of the interesected raycastable objects
controls.jumpEnabled : boolean â
Flag to enable or disable jumping capability.
controls.flyEnabled : boolean â
Flag to enable or disable flying capability.
controls.pressing : Boolean â
Left click on desktop
controls.grabbing : Boolean â
Right click on desktop
controls.floor : THREE.Object3D | null â
The current object below the player, useful for sound effects, collisions.
controls.floorHeight : Number â
The floors y position in world space.
controls.falling : boolean â
Whether player controls are falling
controls.startPosition : Vector3 â
The initial camera position when the scene is loaded. This is used for resetting the player position on fall timeout. You can over-ride this. This can be useful for resetting to a point on a map when the player dies or falls for too long
controls.fallResetTime : Number : 2 â
The time before the player controls resets to the original startPostion when falling for x seconds. The default is 2 (seconds).
To disable this use: controls.fallResetTime = -1
Desktop â
js
// Disable or enable using pointer lock. true by default
controls.desktop.pointerLockEnabled = true | false
controls.desktop.enabled = true | false
controls.desktop.cursor -> cursor DOM element
// You can create your own desktop specific controls, e.g.
controls.desktop = {
update: (delta)=>{ /* your logic '*/ }
}Mobile â
js
controls.mobile.enable();
controls.mobile.disable();
controls.mobile = {
update: (delta) => {
/* your logic '*/
},
};XR â
controls.locomotion : Locomotion â
Handles locomotion within the VR environment.
controls.locomotion.enabled : boolean â
Flag to enable or disable locomotion.
controls['left' or 'right'] : Hand â
Left/right controller object, containing state and interaction data for that hand.
Hand : Object â
Represents the right control interface, including position, rotation, and interaction states.
| Name | Type | Description |
|---|---|---|
| position | THREE.Vector3 | The current position in 3D space. |
| rotation | THREE.Euler | The current rotation using Euler angles. |
| quaternion | THREE.Quaternion | The current orientation using quaternion. |
| pressing | boolean | Indicates if the control is currently being pressed. |
| grabbing | boolean | Indicates if the control is currently grabbing an object. |
| gamepad | Gamepad | The associated gamepad device, if any. |
| pulse | function | Function to trigger haptic feedback. Takes: (intensity, duration) |
| hand | {} | Object/Dict storing references to each hand/finger joint |
| raycaster | THREE.Raycaster | The raycaster for detecting intersections. |
| ray | THREE.Ray | The current ray used for intersection tests. |
| intersections | Array | A list of current intersections detected by the raycaster. |
| inputSource | number | 0 = not connected, 1 = controller, 2 = hand tracking |
Hand joints: â
js
'wrist'
'thumb-metacarpal'
'thumb-phalanx-proximal'
'thumb-phalanx-distal'
'index-finger-phalanx-proximal'
'index-finger-phalanx-intermediate'
'index-finger-phalanx-distal'
'middle-finger-phalanx-proximal'
'middle-finger-phalanx-intermediate'
'middle-finger-phalanx-distal'
'ring-finger-phalanx-proximal'
'ring-finger-phalanx-intermediate'
'ring-finger-phalanx-distal'
'pinky-finger-phalanx-proximal'
'pinky-finger-phalanx-intermediate'
'pinky-finger-phalanx-distal'
// Three.Group storing bone position, rotation
controls.left.hand['pinky-finger-phalanx-distal'] -> THREE.Group