UNPKG

hytopia

Version:

The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.

900 lines (401 loc) 11.4 kB
<!-- Do not edit this file. It is automatically generated by API Documenter. --> [Home](./index.md) &gt; [server](./server.md) &gt; [Entity](./server.entity.md) ## Entity class Represents an entity in a world. **Signature:** ```typescript export default class Entity extends RigidBody implements protocol.Serializable ``` **Extends:** [RigidBody](./server.rigidbody.md) **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. <h2>Events</h2> This class is an EventRouter, and instances of it emit events with payloads listed under [EntityEventPayloads](./server.entityeventpayloads.md) ## Example ```typescript 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 <table><thead><tr><th> Constructor </th><th> Modifiers </th><th> Description </th></tr></thead> <tbody><tr><td> [(constructor)(options)](./server.entity._constructor_.md) </td><td> </td><td> Constructs a new instance of the `Entity` class </td></tr> </tbody></table> ## Properties <table><thead><tr><th> Property </th><th> Modifiers </th><th> Type </th><th> Description </th></tr></thead> <tbody><tr><td> [blockHalfExtents](./server.entity.blockhalfextents.md) </td><td> `readonly` </td><td> [Vector3Like](./server.vector3like.md) \| undefined </td><td> The half extends of the visual size of the block entity when blockTextureUri is set. </td></tr> <tr><td> [blockTextureUri](./server.entity.blocktextureuri.md) </td><td> `readonly` </td><td> string \| undefined </td><td> The URI or path to the texture to be used, if this is set, the entity is a block entity. </td></tr> <tr><td> [controller](./server.entity.controller.md) </td><td> `readonly` </td><td> [BaseEntityController](./server.baseentitycontroller.md) \| undefined </td><td> The controller for the entity. </td></tr> <tr><td> [depth](./server.entity.depth.md) </td><td> `readonly` </td><td> number </td><td> The depth (z-axis) of the entity's model with scale consideration or block entity's y\*2 half extents. </td></tr> <tr><td> [height](./server.entity.height.md) </td><td> `readonly` </td><td> number </td><td> The height (y-axis) of the entity's model with scale consideration or block entity's y\*2 half extents. </td></tr> <tr><td> [id](./server.entity.id.md) </td><td> `readonly` </td><td> number \| undefined </td><td> The unique identifier for the entity. </td></tr> <tr><td> [isBlockEntity](./server.entity.isblockentity.md) </td><td> `readonly` </td><td> boolean </td><td> Whether the entity is a block entity. </td></tr> <tr><td> [isEnvironmental](./server.entity.isenvironmental.md) </td><td> `readonly` </td><td> boolean </td><td> Whether the entity is environmental, if true it will not invoke its tick function or change position. </td></tr> <tr><td> [isModelEntity](./server.entity.ismodelentity.md) </td><td> `readonly` </td><td> boolean </td><td> Whether the entity is a model entity. </td></tr> <tr><td> [isSpawned](./server.entity.isspawned.md) </td><td> `readonly` </td><td> boolean </td><td> Whether the entity is spawned. </td></tr> <tr><td> [modelAnimationsPlaybackRate](./server.entity.modelanimationsplaybackrate.md) </td><td> `readonly` </td><td> number </td><td> The playback rate of the entity's model animations. </td></tr> <tr><td> [modelHiddenNodes](./server.entity.modelhiddennodes.md) </td><td> `readonly` </td><td> ReadonlySet&lt;string&gt; </td><td> The nodes to hide on the entity's model. </td></tr> <tr><td> [modelLoopedAnimations](./server.entity.modelloopedanimations.md) </td><td> `readonly` </td><td> ReadonlySet&lt;string&gt; </td><td> The looped animations to start when the entity is spawned. </td></tr> <tr><td> [modelPreferredShape](./server.entity.modelpreferredshape.md) </td><td> `readonly` </td><td> [ColliderShape](./server.collidershape.md) \| undefined </td><td> The preferred shape of the entity's model when automatically generating its collider when no explicit colliders are provided. </td></tr> <tr><td> [modelScale](./server.entity.modelscale.md) </td><td> `readonly` </td><td> number </td><td> The scale of the entity's model. </td></tr> <tr><td> [modelShownNodes](./server.entity.modelshownnodes.md) </td><td> `readonly` </td><td> ReadonlySet&lt;string&gt; </td><td> The nodes to show on the entity's model, overriding hidden nodes. </td></tr> <tr><td> [modelTextureUri](./server.entity.modeltextureuri.md) </td><td> `readonly` </td><td> string \| undefined </td><td> The URI or path to the texture that overrides the model entity's default texture. </td></tr> <tr><td> [modelUri](./server.entity.modeluri.md) </td><td> `readonly` </td><td> string \| undefined </td><td> The URI or path to the .gltf model asset to be used for the entity. </td></tr> <tr><td> [name](./server.entity.name.md) </td><td> `readonly` </td><td> string </td><td> The name of the entity. </td></tr> <tr><td> [opacity](./server.entity.opacity.md) </td><td> `readonly` </td><td> number </td><td> The opacity of the entity between 0 and 1. 0 is fully transparent, 1 is fully opaque. </td></tr> <tr><td> [parent](./server.entity.parent.md) </td><td> `readonly` </td><td> [Entity](./server.entity.md) \| undefined </td><td> The parent entity of the entity. </td></tr> <tr><td> [parentNodeName](./server.entity.parentnodename.md) </td><td> `readonly` </td><td> string \| undefined </td><td> The name of the parent's node (if parent is a model entity) this entity is attached to when spawned. </td></tr> <tr><td> [tag](./server.entity.tag.md) </td><td> `readonly` </td><td> string \| undefined </td><td> An arbitrary identifier tag of the entity. Useful for your own logic. </td></tr> <tr><td> [tintColor](./server.entity.tintcolor.md) </td><td> `readonly` </td><td> [RgbColor](./server.rgbcolor.md) \| undefined </td><td> The tint color of the entity. </td></tr> <tr><td> [width](./server.entity.width.md) </td><td> `readonly` </td><td> number </td><td> The width (x-axis) of the entity's model with scale consideration or block entity's x\*2 half extents. </td></tr> <tr><td> [world](./server.entity.world.md) </td><td> `readonly` </td><td> [World](./server.world.md) \| undefined </td><td> The world the entity is in. </td></tr> </tbody></table> ## Methods <table><thead><tr><th> Method </th><th> Modifiers </th><th> Description </th></tr></thead> <tbody><tr><td> [despawn()](./server.entity.despawn.md) </td><td> </td><td> Despawns the entity and all children from the world. </td></tr> <tr><td> [setController(controller)](./server.entity.setcontroller.md) </td><td> </td><td> Sets the controller for the entity. </td></tr> <tr><td> [setModelAnimationsPlaybackRate(playbackRate)](./server.entity.setmodelanimationsplaybackrate.md) </td><td> </td><td> Sets the playback rate of all animations on the entity's model. </td></tr> <tr><td> [setModelHiddenNodes(modelHiddenNodes)](./server.entity.setmodelhiddennodes.md) </td><td> </td><td> Sets the nodes to hide on the entity's model. Matched nodes will be hidden for all players. Uses case insensitive substring matching. </td></tr> <tr><td> [setModelShownNodes(modelShownNodes)](./server.entity.setmodelshownnodes.md) </td><td> </td><td> Sets the nodes to show on the entity's model, overriding hidden nodes. Matched nodes will be shown for all players. Uses case insensitive substring matching. </td></tr> <tr><td> [setModelTextureUri(modelTextureUri)](./server.entity.setmodeltextureuri.md) </td><td> </td><td> Sets the texture uri of the entity's model. Setting this overrides the model's default texture. </td></tr> <tr><td> [setOpacity(opacity)](./server.entity.setopacity.md) </td><td> </td><td> Sets the opacity of the entity. </td></tr> <tr><td> [setParent(parent, parentNodeName, position, rotation)](./server.entity.setparent.md) </td><td> </td><td> Sets the parent of the entity and resets this entity's position and rotation. </td></tr> <tr><td> [setTintColor(tintColor)](./server.entity.settintcolor.md) </td><td> </td><td> Sets the tint color of the entity. </td></tr> <tr><td> [spawn(world, position, rotation)](./server.entity.spawn.md) </td><td> </td><td> Spawns the entity in the world. </td></tr> <tr><td> [startModelLoopedAnimations(animations)](./server.entity.startmodelloopedanimations.md) </td><td> </td><td> Starts looped animations for the entity, blending with other animations currently playing. </td></tr> <tr><td> [startModelOneshotAnimations(animations)](./server.entity.startmodeloneshotanimations.md) </td><td> </td><td> Starts a oneshot animation for the entity, blending with other animations currently playing. </td></tr> <tr><td> [stopAllModelAnimations(excludedAnimations)](./server.entity.stopallmodelanimations.md) </td><td> </td><td> Stops all looped and oneshot animations for the entity, optionally excluded the provided animations from stopping. </td></tr> <tr><td> [stopAllModelLoopedAnimations(excludedAnimations)](./server.entity.stopallmodelloopedanimations.md) </td><td> </td><td> Stops all looped animations for the entity, optionally excluded the provided animations from stopping. </td></tr> <tr><td> [stopAllModelOneshotAnimations(excludedAnimations)](./server.entity.stopallmodeloneshotanimations.md) </td><td> </td><td> Stops all oneshot animations for the entity, optionally excluded the provided animations from stopping. </td></tr> <tr><td> [stopModelAnimations(animations)](./server.entity.stopmodelanimations.md) </td><td> </td><td> Stops the provided model animations for the entity. </td></tr> </tbody></table>