Class: RigidControls
Inspired by THREE.JS's PointerLockControls, a rigid body based first person controls.
Example
// Create the controls.
const controls = new RigidControls(
camera,
renderer.domElement,
world
);
// Printing the voxel that the client is in.
console.log(controls.voxel);
// Call the controls update function in the render loop.
controls.update();
Hierarchy
-
EventEmitter↳
RigidControls
Implements
Constructors
constructor
• new RigidControls(camera, domElement, world, options?): RigidControls
Construct a Voxelize rigid body based first person controls. This adds a rigid body to the world's physics engine, and applies movement to the camera.
Parameters
| Name | Type | Description |
|---|---|---|
camera | PerspectiveCamera | The camera to apply the controls to. |
domElement | HTMLElement | The DOM element to apply the controls to. |
world | World<any> | The world to apply the controls to. |
options | Partial<RigidControlsOptions> | The options to initialize the controls with. |
Returns
Overrides
EventEmitter.constructor
Properties
INPUT_IDENTIFIER
▪ Static Readonly INPUT_IDENTIFIER: "voxelize-rigid-controls"
This is the identifier that is used to bind the rigid controls' keyboard inputs when RigidControls.connect is called.
arm
• Optional arm: Arm
A potential link to a Arm instance. This can be added by calling RigidControls.attachArm to add a mesh for the first person view.
body
• body: RigidBody
The physical rigid body of the client, dimensions described by:
options.bodyWidthoptions.bodyHeightoptions.bodyDepth
camera
• camera: PerspectiveCamera
Reference linking to the Voxelize camera instance.
character
• Optional character: Character
A potential link to a Character instance. This can be added by calling RigidControls.attachCharacter to add a mesh for 2nd and 3rd person view.
domElement
• domElement: HTMLElement
The DOM element that pointerlock controls are applied to.
inputs
• Optional inputs: Inputs<any>
Reference linking to the Voxelize Inputs instance. You can link an inputs manager by calling RigidControls.connect, which registers the keyboard inputs for the controls.
isLocked
• isLocked: boolean = false
Flag indicating whether pointerlock controls have control over the cursor.
movements
• movements: Object
Whether or not the client has certain movement potentials. For example, if the forward
key is pressed, then "front" would be true. Vice versa for "back".
Type declaration
| Name | Type |
|---|---|
back | boolean |
down | boolean |
front | boolean |
left | boolean |
right | boolean |
sprint | boolean |
up | boolean |
object
• object: Group<Object3DEventMap>
A THREE.JS object, parent to the camera for pointerlock controls.
options
• options: RigidControlsOptions
Parameters to initialize the Voxelize controls.
ownID
• ownID: string = ""
The client's own peer ID. This is set when the client first connects to the server.
state
• state: RigidControlState
The state of the control, indicating things like whether or not the client is running.
teleportCount
• teleportCount: number = 0
How many times these controls have been teleported. A reader that follows the body frame by frame (a fall meter, a trail) starts over when it changes: the body did not travel the distance a teleport moves it.
world
• world: World<any>
Reference linking to the Voxelize world instance.
Accessors
chunk
• get chunk(): Coords2
The chunk that the client is situated in.
Returns
flyMode
• get flyMode(): boolean
Whether if the client is in fly mode. Fly mode means client can fly but not through blocks.
Returns
boolean
ghostMode
• get ghostMode(): boolean
Whether if the client is in ghost mode. Ghost mode means client can fly through blocks.
Returns
boolean
isCrouching
• get isCrouching(): boolean
Returns
boolean
isSwimPoseActive
• get isSwimPoseActive(): boolean