Skip to content

marble3 / CharacterController

Class: CharacterController ​

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

Moves a character's body by setting its velocity every frame: along the walk direction on ground it can stand on, following slopes, and under gravity otherwise. Ground steeper than about 37° is not walkable: the character slides down it and cannot jump from it.

The body must not rotate (CharacterEntity sets its angular factor to 0): the feet are taken to be straight below its centre.

Constructors ​

Constructor ​

new CharacterController(body, opts?): CharacterController

Defined in: src/entity/character-controller.ts:68

Parameters ​

body ​

btRigidBody

opts? ​

CharacterControllerOptions = {}

Returns ​

CharacterController

Properties ​

grounded ​

grounded: boolean = false

Defined in: src/entity/character-controller.ts:48

Whether the last update() found walkable ground underfoot.


jumpSpeed ​

jumpSpeed: number

Defined in: src/entity/character-controller.ts:52

Take-off speed of a jump, in units per second.


walkSpeed ​

walkSpeed: number

Defined in: src/entity/character-controller.ts:50

Units per second.

Methods ​

dispose() ​

dispose(): void

Defined in: src/entity/character-controller.ts:74

Returns ​

void


jump() ​

jump(): void

Defined in: src/entity/character-controller.ts:87

Jumps on the next update() if grounded then; otherwise the request is dropped, not queued.

Returns ​

void


reset() ​

reset(): void

Defined in: src/entity/character-controller.ts:92

Forgets the fall speed built up so far. Call it when teleporting a character that was falling.

Returns ​

void


setWalkDirection() ​

setWalkDirection(dir): void

Defined in: src/entity/character-controller.ts:82

Sets the direction to walk in until told otherwise; y is ignored. A unit vector walks at walkSpeed, a shorter one proportionally slower.

Parameters ​

dir ​

Vector3

Returns ​

void


update() ​

update(world?, dt?): void

Defined in: src/entity/character-controller.ts:101

Sets the body's velocity for this frame; CharacterEntity.update() calls it after each physics step. Without a world there is no ground to find, and only the horizontal velocity is driven.

Parameters ​

world? ​

btDiscreteDynamicsWorld

dt? ​

number = ...

Returns ​

void