Home > server > SimpleEntityController
A simple entity controller with basic movement functions.
Signature:
export default class SimpleEntityController extends BaseEntityController Extends: BaseEntityController
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.
// 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);
},
});|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
string[] |
The animations to loop when the entity is idle. | ||
|
number | undefined |
The speed at which to loop the idle animations. | ||
|
string[] |
The animations to play when the entity jumps. | ||
|
string[] |
The animations to loop when the entity is moving. | ||
|
number | undefined |
The speed at which to loop the move animations. | ||
|
number |
The speed at which to move the entity. Can be altered while moving. |
|
Method |
Modifiers |
Description |
|---|---|---|
|
Rotates the entity at a given speed to face a target coordinate. | ||
|
Applies an upwards impulse to the entity to simulate a jump, only supported for entities with dynamic rigid body types. | ||
|
Moves the entity at a given speed in a straight line to a target coordinate. | ||
|
Override of the BaseEntityController.spawn() method. Starts the set idle animations (if any) when the entity is spawned. |