Skip to content

Latest commit

 

History

History
253 lines (118 loc) · 3.91 KB

File metadata and controls

253 lines (118 loc) · 3.91 KB

Home > server > SimpleEntityController

SimpleEntityController class

A simple entity controller with basic movement functions.

Signature:

export default class SimpleEntityController extends BaseEntityController 

Extends: BaseEntityController

Remarks

This class implements simple movement methods that serve as a way to add realistic movement and rotational facing functionality to an entity. This is also a great base to extend for your own more complex entity controller that implements things like pathfinding. Compatible with entities that have kinematic or dynamic rigid body types.

Example

// Create a custom entity controller for myEntity, prior to spawning it.
myEntity.setController(new SimpleEntityController());

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

// Move the entity at a speed of 4 blocks
// per second to the coordinate (10, 1, 10).
// console.log when we reach the target.
myEntity.controller.move({ x: 10, y: 1, z: 10 }, 4, {
  moveCompleteCallback: endPosition => {
    console.log('Finished moving to', endPosition);
  },
});

Properties

Property

Modifiers

Type

Description

idleLoopedAnimations

string[]

The animations to loop when the entity is idle.

idleLoopedAnimationsSpeed

number | undefined

The speed at which to loop the idle animations.

jumpOneshotAnimations

string[]

The animations to play when the entity jumps.

moveLoopedAnimations

string[]

The animations to loop when the entity is moving.

moveLoopedAnimationsSpeed

number | undefined

The speed at which to loop the move animations.

moveSpeed

number

The speed at which to move the entity. Can be altered while moving.

Methods

Method

Modifiers

Description

face(target, speed, options)

Rotates the entity at a given speed to face a target coordinate.

jump(height)

Applies an upwards impulse to the entity to simulate a jump, only supported for entities with dynamic rigid body types.

move(target, speed, options)

Moves the entity at a given speed in a straight line to a target coordinate.

spawn(entity)

Override of the BaseEntityController.spawn() method. Starts the set idle animations (if any) when the entity is spawned.