Skip to content

Latest commit

 

History

History
766 lines (344 loc) · 9.37 KB

File metadata and controls

766 lines (344 loc) · 9.37 KB

Home > server > Entity

Entity class

Represents an entity in a world.

Signature:

export default class Entity extends RigidBody implements protocol.Serializable 

Extends: RigidBody

Implements: protocol.Serializable

Remarks

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.

Events

This class is an EventRouter, and instances of it emit events with payloads listed under EntityEventPayloads

Example

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 });

Constructors

Constructor

Modifiers

Description

(constructor)(options)

Constructs a new instance of the Entity class

Properties

Property

Modifiers

Type

Description

blockHalfExtents

readonly

Vector3Like | undefined

The half extends of the visual size of the block entity when blockTextureUri is set.

blockTextureUri

readonly

string | undefined

The URI or path to the texture to be used, if this is set, the entity is a block entity.

controller

readonly

BaseEntityController | undefined

The controller for the entity.

height

readonly

number

The height of the entity's model or block entity's y*2 half extents.

id

readonly

number | undefined

The unique identifier for the entity.

isBlockEntity

readonly

boolean

Whether the entity is a block entity.

isModelEntity

readonly

boolean

Whether the entity is a model entity.

isSpawned

readonly

boolean

Whether the entity is spawned.

modelAnimationsPlaybackRate

readonly

number

The playback rate of the entity's model animations.

modelHiddenNodes

readonly

ReadonlySet<string>

The nodes to hide on the entity's model.

modelLoopedAnimations

readonly

ReadonlySet<string>

The looped animations to start when the entity is spawned.

modelPreferredShape

readonly

ColliderShape | undefined

The preferred shape of the entity's model when automatically generating its collider when no explicit colliders are provided.

modelScale

readonly

number

The scale of the entity's model.

modelUri

readonly

string | undefined

The URI or path to the .gltf model asset to be used for the entity.

name

readonly

string

The name of the entity.

opacity

readonly

number

The opacity of the entity between 0 and 1. 0 is fully transparent, 1 is fully opaque.

parent

readonly

Entity | undefined

The parent entity of the entity.

parentNodeName

readonly

string | undefined

The name of the parent's node (if parent is a model entity) this entity is attached to when spawned.

tag

readonly

string | undefined

An arbitrary identifier tag of the entity. Useful for your own logic.

tintColor

readonly

RgbColor | undefined

The tint color of the entity.

world

readonly

World | undefined

The world the entity is in.

Methods

Method

Modifiers

Description

despawn()

Despawns the entity and all children from the world.

setController(controller)

Sets the controller for the entity.

setModelAnimationsPlaybackRate(playbackRate)

Sets the playback rate of all animations on the entity's model.

setModelHiddenNodes(modelHiddenNodes)

Sets the nodes to hide on the entity's model. Matched nodes will be hidden for all players. Uses case insensitive substring matching.

setOpacity(opacity)

Sets the opacity of the entity.

setParent(parent, parentNodeName, position, rotation)

Sets the parent of the entity and resets this entity's position and rotation.

setTintColor(tintColor)

Sets the tint color of the entity.

spawn(world, position, rotation)

Spawns the entity in the world.

startModelLoopedAnimations(animations)

Starts looped animations for the entity, blending with other animations currently playing.

startModelOneshotAnimations(animations)

Starts a oneshot animation for the entity, blending with other animations currently playing.

stopAllModelAnimations(excludedAnimations)

Stops all looped and oneshot animations for the entity, optionally excluded the provided animations from stopping.

stopAllModelLoopedAnimations(excludedAnimations)

Stops all looped animations for the entity, optionally excluded the provided animations from stopping.

stopAllModelOneshotAnimations(excludedAnimations)

Stops all oneshot animations for the entity, optionally excluded the provided animations from stopping.

stopModelAnimations(animations)

Stops the provided model animations for the entity.