Skip to content

Latest commit

 

History

History
715 lines (312 loc) · 10.1 KB

File metadata and controls

715 lines (312 loc) · 10.1 KB

Home > server > DefaultPlayerEntityController

DefaultPlayerEntityController class

The player entity controller implementation.

Signature:

export default class DefaultPlayerEntityController extends BaseEntityController 

Extends: BaseEntityController

Remarks

This class extends BaseEntityController and implements the default movement, platforming, jump, swimming, and other basic logic for the default player entity. We recommend you extend this class if you'd like to implement additional logic on top of the DefaultPlayerEntityController implementation.

Example

// Create a custom entity controller for myEntity, prior to spawning it.
myEntity.setController(new DefaultPlayerEntityController({
  jumpVelocity: 10,
  runVelocity: 8,
  walkVelocity: 4,
}));

// Spawn the entity in the world.
myEntity.spawn(world, { x: 53, y: 10, z: 23 });

Constructors

Constructor

Modifiers

Description

(constructor)(options)

Constructs a new instance of the DefaultPlayerEntityController class

Properties

Property

Modifiers

Type

Description

applyDirectionalMovementRotations

boolean

Whether to apply directional rotations to the entity while moving, defaults to true.

autoCancelMouseLeftClick

boolean

Whether to automatically cancel left click input after first processed tick, defaults to true.

canJump

(controller: DefaultPlayerEntityController) => boolean

A function allowing custom logic to determine if the entity can jump.

canRun

(controller: DefaultPlayerEntityController) => boolean

A function allowing custom logic to determine if the entity can run.

canSwim

(controller: DefaultPlayerEntityController) => boolean

A function allowing custom logic to determine if the entity can swim.

canWalk

(controller: DefaultPlayerEntityController) => boolean

A function allowing custom logic to determine if the entity can walk.

idleLoopedAnimations

string[]

The looped animation(s) that will play when the entity is idle.

interactOneshotAnimations

string[]

The oneshot animation(s) that will play when the entity interacts (left click)

isActivelyMoving

readonly

boolean

Whether the entity is moving from player inputs.

isGrounded

readonly

boolean

Whether the entity is grounded.

isOnPlatform

readonly

boolean

Whether the entity is on a platform, a platform is any entity with a kinematic rigid body.

isSwimming

readonly

boolean

Whether the entity is swimming, this is determined by if the entity is in a liquid block.

jumpLandHeavyOneshotAnimations

string[]

The oneshot animation(s) that will play when the entity lands with a high velocity.

jumpLandLightOneshotAnimations

string[]

The oneshot animation(s) that will play when the entity lands after jumping or being airborne.

jumpOneshotAnimations

string[]

The oneshot animation(s) that will play when the entity is jumping.

jumpVelocity

number

The upward velocity applied to the entity when it jumps.

platform

readonly

Entity | undefined

The platform the entity is on, if any.

runLoopedAnimations

string[]

The looped animation(s) that will play when the entity is running.

runVelocity

number

The normalized horizontal velocity applied to the entity when it runs.

sticksToPlatforms

boolean

Whether the entity sticks to platforms.

swimFastVelocity

number

The normalized horizontal velocity applied to the entity when it swims fast (equivalent to running).

swimGravity

number

The gravity modifier applied to the entity when swimming.

swimIdleLoopedAnimations

string[]

The looped animation(s) that will play when the entity is not moving while swimming.

swimLoopedAnimations

string[]

The looped animation(s) that will play when the entity is swimming in any direction.

swimMaxGravityVelocity

number

The maximum downward velocity that the entity can reach when affected by gravity while swimming.

swimSlowVelocity

number

The normalized horizontal velocity applied to the entity when it swims slowly (equivalent to walking).

swimUpwardVelocity

number

The upward velocity applied to the entity when swimming.

walkLoopedAnimations

string[]

The looped animation(s) that will play when the entity is walking.

walkVelocity

number

The normalized horizontal velocity applied to the entity when it walks.

Methods

Method

Modifiers

Description

attach(entity)

Called when the controller is attached to an entity.

spawn(entity)

Called when the controlled entity is spawned. In DefaultPlayerEntityController, this function is used to create the colliders for the entity for wall and ground detection.

tickWithPlayerInput(entity, input, cameraOrientation, deltaTimeMs)

Ticks the player movement for the entity controller, overriding the default implementation. If the entity to tick is a child entity, only the event will be emitted but the default movement logic will not be applied.