Skip to content

marble3 / Player

Class: Player ​

Defined in: src/player/player.ts:56

The first-person player: a capsule that walks where its input points, with the camera riding 2 units above its feet. It picks its controls for the device: keyboard and mouse-look (DesktopController) or an on-screen stick, swipe and jump button (MobileController).

It moves only while its input is captured (on desktop, while the pointer is locked). If it drops 30 units below the first ground it stood on, it is put back there.

Extends ​

Constructors ​

Constructor ​

new Player(opts): Player

Defined in: src/player/player.ts:68

Parameters ​

opts ​

PlayerOptions

Returns ​

Player

Overrides ​

CharacterEntity.constructor

Properties ​

body ​

body: btRigidBody

Defined in: src/entity/physic.ts:55

Inherited from ​

CharacterEntity.body


camera ​

camera: PerspectiveCamera

Defined in: src/player/player.ts:57


controller ​

controller: CharacterController

Defined in: src/entity/character.ts:29

Takes the walk direction and jumps, and reports grounded.

Inherited from ​

CharacterEntity.controller


disposed ​

protected disposed: boolean = false

Defined in: src/entity/graphic.ts:19

Inherited from ​

GraphicEntity.disposed


id ​

id: string

Defined in: src/entity/graphic.ts:16

Unique per entity. Keys FPS.entities, and is stamped on collision shapes so a ray or contact hit resolves back to its entity.

Inherited from ​

CharacterEntity.id


inputController ​

inputController: PlayerInput

Defined in: src/player/player.ts:59

The input read every frame. Suspend it with suspendInput.


inventory ​

readonly inventory: Inventory

Defined in: src/player/player.ts:60


mass ​

mass: number

Defined in: src/entity/physic.ts:57

Inherited from ​

CharacterEntity.mass


mesh? ​

protected optional mesh?: Mesh<BufferGeometry<NormalBufferAttributes>, Material | Material[], Object3DEventMap>

Defined in: src/entity/physic.ts:59

Inherited from ​

CharacterEntity.mesh


shape ​

shape: btCollisionShape

Defined in: src/entity/physic.ts:56

Inherited from ​

CharacterEntity.shape


three ​

three: Group

Defined in: src/entity/graphic.ts:18

The entity's node in the scene; FPS.add() puts it there. Add your meshes under it.

Inherited from ​

CharacterEntity.three

Accessors ​

position ​

Get Signature ​

get position(): Vector3

Defined in: src/entity/character.ts:53

Where the body is. Setting it teleports the character and clears the body's velocity; after a fall, also call controller.reset(), which holds the fall speed.

Returns ​

Vector3

Set Signature ​

set position(position): void

Defined in: src/entity/character.ts:58

Where the body is, as a new vector. Setting it teleports the body and its mesh, and leaves the body's velocity as it was.

Parameters ​
position ​

Vector3

Returns ​

void

Inherited from ​

CharacterEntity.position


walkSpeed ​

Get Signature ​

get walkSpeed(): number

Defined in: src/entity/character.ts:46

The controller's walk speed, in units per second.

Returns ​

number

Set Signature ​

set walkSpeed(v): void

Defined in: src/entity/character.ts:47

Parameters ​
v ​

number

Returns ​

void

Inherited from ​

CharacterEntity.walkSpeed

Methods ​

dispose() ​

dispose(): void

Defined in: src/player/player.ts:135

Frees the body, its motion state and the shape, then the Three resources. The body must already be out of the world: use FPS.remove(), which does both.

Returns ​

void

Overrides ​

CharacterEntity.dispose


registerPhysics() ​

registerPhysics(world): void

Defined in: src/entity/physic.ts:112

Parameters ​

world ​

btDiscreteDynamicsWorld

Returns ​

void

Inherited from ​

CharacterEntity.registerPhysics


unregisterPhysics() ​

unregisterPhysics(world): void

Defined in: src/entity/physic.ts:116

Parameters ​

world ​

btDiscreteDynamicsWorld

Returns ​

void

Inherited from ​

CharacterEntity.unregisterPhysics


update() ​

update(delta?, engine?): void

Defined in: src/player/player.ts:97

Called every frame the world is not paused, with the seconds since the last frame and the FPS the entity lives in (for its world and entities).

Parameters ​

delta? ​

number = 0

engine? ​

FPS

Returns ​

void

Overrides ​

CharacterEntity.update