Skip to main content

Class: MobileRigidControls

Mobile-specific rigid body controls for touch-based input. Extends RigidControls but removes pointer lock and keyboard bindings, instead exposing methods for joystick, jump button, and touch-look input.

Hierarchy​

Constructors​

constructor​

• new MobileRigidControls(camera, domElement, world, options?): MobileRigidControls

Construct mobile rigid body controls with touch-based input.

Parameters​

NameTypeDescription
cameraPerspectiveCameraThe camera to apply the controls to.
domElementHTMLElementThe DOM element (not used for pointer lock on mobile).
worldWorld<any>The world to apply the controls to.
optionsPartial<RigidControlsOptions>The options to initialize the controls with.

Returns​

MobileRigidControls

Overrides​

RigidControls.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.

Inherited from​

RigidControls.INPUT_IDENTIFIER


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.

Inherited from​

RigidControls.arm


body​

• body: RigidBody

The physical rigid body of the client, dimensions described by:

  • options.bodyWidth
  • options.bodyHeight
  • options.bodyDepth

Inherited from​

RigidControls.body


camera​

• camera: PerspectiveCamera

Reference linking to the Voxelize camera instance.

Inherited from​

RigidControls.camera


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.

Inherited from​

RigidControls.character


domElement​

• domElement: HTMLElement

The DOM element that pointerlock controls are applied to.

Inherited from​

RigidControls.domElement


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.

Inherited from​

RigidControls.inputs


isLocked​

• isLocked: boolean = false

Flag indicating whether pointerlock controls have control over the cursor.

Inherited from​

RigidControls.isLocked


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​

NameType
backboolean
downboolean
frontboolean
leftboolean
rightboolean
sprintboolean
upboolean

Inherited from​

RigidControls.movements


object​

• object: Group<Object3DEventMap>

A THREE.JS object, parent to the camera for pointerlock controls.

Inherited from​

RigidControls.object


options​

• options: RigidControlsOptions

Parameters to initialize the Voxelize controls.

Inherited from​

RigidControls.options


ownID​

• ownID: string = ""

The client's own peer ID. This is set when the client first connects to the server.

Inherited from​

RigidControls.ownID


state​

• state: RigidControlState

The state of the control, indicating things like whether or not the client is running.

Inherited from​

RigidControls.state


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.

Inherited from​

RigidControls.teleportCount


world​

• world: World<any>

Reference linking to the Voxelize world instance.

Inherited from​

RigidControls.world

Accessors​

chunk​

• get chunk(): Coords2

The chunk that the client is situated in.

Returns​

Coords2

Inherited from​

RigidControls.chunk


flyMode​

• get flyMode(): boolean

Whether if the client is in fly mode. Fly mode means client can fly but not through blocks.

Returns​

boolean

Inherited from​

RigidControls.flyMode


ghostMode​

• get ghostMode(): boolean

Whether if the client is in ghost mode. Ghost mode means client can fly through blocks.

Returns​

boolean

Inherited from​

RigidControls.ghostMode


isCrouching​

• get isCrouching(): boolean

Returns​

boolean

Inherited from​

RigidControls.isCrouching


isSwimPoseActive​

• get isSwimPoseActive(): boolean

Returns​

boolean

Inherited from​

RigidControls.isSwimPoseActive


isSwimming​

• get isSwimming(): boolean

Returns​

boolean

Inherited from​

RigidControls.isSwimming


isSwimmingIdleStanding​

• get isSwimmingIdleStanding(): boolean

Returns​

boolean

Inherited from​

RigidControls.isSwimmingIdleStanding


position​

• get position(): Vector3

The 3D world coordinates that the client is at. This is where the bottom of the client's body is located.

Returns​

Vector3

Inherited from​

RigidControls.position


voxel​

• get voxel(): Coords3

The voxel coordinates that the client is at. This is where the bottom of the client's body is located, floored to the voxel coordinate.

Returns​

Coords3

Inherited from​

RigidControls.voxel

Methods​

attachArm​

▸ attachArm(arm): void

Attach a Arm to this controls instance. This can be seen in 1st person mode.

Parameters​

NameTypeDescription
armArmThe Arm to attach to this controls instance.

Returns​

void

Inherited from​

RigidControls.attachArm


attachCharacter​

▸ attachCharacter(character, newLerpFactor?, newRotationLerpFactor?): void

Attach a Character to this controls instance. This can be seen in 2nd/3rd person mode.

The character's height drives the collision height and eye level so the camera sits where the model's eyes are. Width and depth deliberately stay at options.bodyWidth/options.bodyDepth: the visual model is wider than the hull should be (a model-width hull could not fit through an open door's leaf gap), and a collision hull narrower than the body is the norm players expect.

Parameters​

NameTypeDefault valueDescription
characterCharacterundefinedThe Character to attach to this controls instance.
newLerpFactornumber1The position lerp factor to use for the character. 1 pins the body to the eye, which is what the controls' own body wants: its pose is local and known every frame, not a network sample.
newRotationLerpFactor?numberundefinedThe rotation lerp factor for the character's head and body; left as the character's own setting when omitted.

Returns​

void

Inherited from​

RigidControls.attachCharacter


connect​

▸ connect(): () => void

Sets up all event listeners for controls, including:

  • Mouse move event
  • Pointer-lock events
  • Canvas click event
  • Key up/down events
  • Control lock/unlock events

This function returns a function that can be called to disconnect the controls. Keep in mind that if Inputs.remap is used to remap any controls, they will not be unbound when the returned function is called.

Returns​

fn

▸ (): void

Returns​

void

Options

inputs Inputs instance to bind the controls to.

Options

namespace The namespace to bind the controls to.

Overrides​

RigidControls.connect


getDirection​

▸ getDirection(): Vector3

Get the direction that the client is looking at.

Returns​

Vector3

Inherited from​

RigidControls.getDirection


lock​

▸ lock(): void

Lock the cursor to the game, calling requestPointerLock on the dom element. Needs to be called within a DOM event listener callback!

Returns​

void

Overrides​

RigidControls.lock


lookAt​

▸ lookAt(x, y, z): void

Make the client look at a coordinate.

Parameters​

NameTypeDescription
xnumberX-coordinate to look at.
ynumberY-coordinate to look at.
znumberZ-coordinate to look at.

Returns​

void

Inherited from​

RigidControls.lookAt


moveForward​

▸ moveForward(distance): void

Move the client forward/backward by a certain distance.

Parameters​

NameTypeDescription
distancenumberDistance to move forward by.

Returns​

void

Inherited from​

RigidControls.moveForward


moveRight​

▸ moveRight(distance): void

Move the client left/right by a certain distance.

Parameters​

NameTypeDescription
distancenumberDistance to move left/right by.

Returns​

void

Inherited from​

RigidControls.moveRight


on​

▸ on(event, listener): MobileRigidControls

An event handler for when the pointerlock is locked/unlocked. The events supported so far are:

  • lock: When the pointerlock is locked.
  • unlock: When the pointerlock is unlocked.

Parameters​

NameTypeDescription
event"lock" | "unlock"The event name, either lock or unlock.
listener() => voidThe listener to call when the event is emitted.

Returns​

MobileRigidControls

The controls instance for chaining.

Inherited from​

RigidControls.on


onMessage​

▸ onMessage(message): void

Parameters​

NameType
messageMessageProtocol<any, any, any, [number, number, number]>

Returns​

void

Inherited from​

RigidControls.onMessage


reset​

▸ reset(): void

Reset the controls instance. This will reset the camera's position and rotation, and reset all movements.

Returns​

void

Inherited from​

RigidControls.reset


resetMovements​

▸ resetMovements(): void

Reset all movement flags to false. Useful when exiting play mode or pausing.

Returns​

void

Overrides​

RigidControls.resetMovements


restoreSwimming​

▸ restoreSwimming(): void

Returns​

void

Inherited from​

RigidControls.restoreSwimming


setDirection​

▸ setDirection(dx, dy, dz): void

Parameters​

NameType
dxnumber
dynumber
dznumber

Returns​

void

Inherited from​

RigidControls.setDirection


setJumping​

▸ setJumping(pressed): void

Set jump state from button input.

Parameters​

NameTypeDescription
pressedbooleanWhether the jump button is currently pressed

Returns​

void


setLookDirection​

▸ setLookDirection(deltaX, deltaY): void

Update camera rotation from touch drag input. Mimics mouse movement for looking around.

Parameters​

NameTypeDescription
deltaXnumberHorizontal touch movement in pixels
deltaYnumberVertical touch movement in pixels

Returns​

void


setMovementVector​

▸ setMovementVector(x, y): void

Set movement direction from joystick input. Converts normalized joystick coordinates to movement flags.

Parameters​

NameTypeDescription
xnumberHorizontal input [-1, 1], where -1 is left, 1 is right
ynumberVertical input [-1, 1], where -1 is down/back, 1 is up/front

Returns​

void


snapBodyHeight​

▸ snapBodyHeight(): void

Snap the smoothed body height (the crouch-transition ease) straight to its target and re-derive the eye anchor from the rigid body now. Call this after re-anchoring the body instantaneously — e.g. attaching to a mount — where easing the eye toward the new height would misplace everything derived from the anchor (mount attachment, streamed position) for the duration of the ease.

Returns​

void

Inherited from​

RigidControls.snapBodyHeight


teleport​

▸ teleport(vx, vy, vz): void

Teleport this rigid controls to a new voxel coordinate.

Parameters​

NameTypeDescription
vxnumberThe x voxel coordinate to teleport to.
vynumberThe y voxel coordinate to teleport to.
vznumberThe z voxel coordinate to teleport to.

Returns​

void

Inherited from​

RigidControls.teleport


teleportToExact​

▸ teleportToExact(x, y, z): void

Parameters​

NameType
xnumber
ynumber
znumber

Returns​

void

Inherited from​

RigidControls.teleportToExact


teleportToTop​

▸ teleportToTop(vx?, vz?, yOffset?): void

Teleport the rigid controls to the top of this voxel column.

Parameters​

NameTypeDefault value
vx?numberundefined
vz?numberundefined
yOffsetnumber0

Returns​

void

Inherited from​

RigidControls.teleportToTop


toggleFly​

▸ toggleFly(): void

Toggle fly mode. Fly mode is like ghost mode, but the client can't fly through blocks.

Returns​

void

Inherited from​

RigidControls.toggleFly


toggleGhostMode​

▸ toggleGhostMode(): void

Toggle ghost mode. Ghost mode is when a client can fly through blocks.

Returns​

void

Inherited from​

RigidControls.toggleGhostMode


unlock​

▸ unlock(): void

Unlock the cursor from the game, calling exitPointerLock on the HTML document. Needs to be called within a DOM event listener callback!

Returns​

void

Overrides​

RigidControls.unlock


update​

▸ update(): void

Update for the camera of the game. This should be called in the game update loop. What this does is that it updates the rigid body, and then interpolates the camera's position and rotation to the new position and rotation. If a character is attached, then the character is also updated. If the arm is attached, then the arm is also updated.

Returns​

void

Inherited from​

RigidControls.update