Represents an entity in a world.
Signature:
export default class Entity extends RigidBody implements protocol.Serializable Extends: RigidBody
Implements: protocol.Serializable
Entities are highly configurable and controllable. All entities are created from a .gltf model asset and allow full control of their rigid body and attached collider dynamics.
This class is an EventRouter, and instances of it emit events with payloads listed under EntityEventPayloads
const spider = new Entity({
name: 'Spider',
modelUri: 'models/spider.gltf',
modelLoopedAnimations: [ 'walk' ],
rigidBodyOptions: {
type: RigidBodyType.DYNAMIC,
enabledRotations: { x: false, y: true, z: false },
colliders: [
{
shape: ColliderShape.ROUND_CYLINDER,
borderRadius: 0.1,
halfHeight: 0.225,
radius: 0.5,
tag: 'body',
}
],
},
});
spider.spawn(world, { x: 20, y: 6, z: 10 });|
Constructor |
Modifiers |
Description |
|---|---|---|
|
Constructs a new instance of the |
|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
|
Vector3Like | undefined |
The half extends of the visual size of the block entity when blockTextureUri is set. | |
|
|
string | undefined |
The URI or path to the texture to be used, if this is set, the entity is a block entity. | |
|
|
BaseEntityController | undefined |
The controller for the entity. | |
|
|
number |
The height of the entity's model or block entity's y*2 half extents. | |
|
|
number | undefined |
The unique identifier for the entity. | |
|
|
boolean |
Whether the entity is a block entity. | |
|
|
boolean |
Whether the entity is a model entity. | |
|
|
boolean |
Whether the entity is spawned. | |
|
|
number |
The playback rate of the entity's model animations. | |
|
|
ReadonlySet<string> |
The nodes to hide on the entity's model. | |
|
|
ReadonlySet<string> |
The looped animations to start when the entity is spawned. | |
|
|
ColliderShape | undefined |
The preferred shape of the entity's model when automatically generating its collider when no explicit colliders are provided. | |
|
|
number |
The scale of the entity's model. | |
|
|
string | undefined |
The URI or path to the .gltf model asset to be used for the entity. | |
|
|
string |
The name of the entity. | |
|
|
number |
The opacity of the entity between 0 and 1. 0 is fully transparent, 1 is fully opaque. | |
|
|
Entity | undefined |
The parent entity of the entity. | |
|
|
string | undefined |
The name of the parent's node (if parent is a model entity) this entity is attached to when spawned. | |
|
|
string | undefined |
An arbitrary identifier tag of the entity. Useful for your own logic. | |
|
|
RgbColor | undefined |
The tint color of the entity. | |
|
|
World | undefined |
The world the entity is in. |
|
Method |
Modifiers |
Description |
|---|---|---|
|
Despawns the entity and all children from the world. | ||
|
Sets the controller for the entity. | ||
|
Sets the playback rate of all animations on the entity's model. | ||
|
Sets the nodes to hide on the entity's model. Matched nodes will be hidden for all players. Uses case insensitive substring matching. | ||
|
Sets the opacity of the entity. | ||
|
Sets the parent of the entity and resets this entity's position and rotation. | ||
|
Sets the tint color of the entity. | ||
|
Spawns the entity in the world. | ||
|
Starts looped animations for the entity, blending with other animations currently playing. | ||
|
Starts a oneshot animation for the entity, blending with other animations currently playing. | ||
|
Stops all looped and oneshot animations for the entity, optionally excluded the provided animations from stopping. | ||
|
Stops all looped animations for the entity, optionally excluded the provided animations from stopping. | ||
|
Stops all oneshot animations for the entity, optionally excluded the provided animations from stopping. | ||
|
Stops the provided model animations for the entity. |