hytopia
Version:
The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.
206 lines (101 loc) • 3 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [server](./server.md) > [PlayerEntity](./server.playerentity.md)
## PlayerEntity class
Represents an entity controlled by a player in a world.
When to use: custom player avatars that respond to player input. Do NOT use for: non-player NPCs; use `Entity` with a controller instead.
**Signature:**
```typescript
export default class PlayerEntity extends Entity
```
**Extends:** [Entity](./server.entity.md)
## Remarks
Player entities extend `Entity`<!-- -->. They expect a controller to be set before spawning. Without a controller, player input cannot be processed.
## Example
```typescript
world.onPlayerJoin = player => {
const playerEntity = new PlayerEntity({
player,
name: 'Player',
modelUri: 'models/players/player.gltf',
modelAnimations: [
{ name: 'idle-lower', loopMode: EntityModelAnimationLoopMode.LOOP, play: true },
{ name: 'idle-upper', loopMode: EntityModelAnimationLoopMode.LOOP, play: true },
],
modelScale: 0.5,
});
playerEntity.spawn(world, { x: 10, y: 20, z: 15 });
};
```
\*\*Category:\*\* Entities
## Constructors
<table><thead><tr><th>
Constructor
</th><th>
Modifiers
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
[(constructor)(options)](./server.playerentity._constructor_.md)
</td><td>
</td><td>
Creates a new PlayerEntity instance.
</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>
[isTickWithPlayerInputEnabled](./server.playerentity.istickwithplayerinputenabled.md)
</td><td>
`readonly`
</td><td>
boolean
</td><td>
Whether `tickWithPlayerInput()` is called during the entity's tick.
\*\*Category:\*\* Entities
</td></tr>
<tr><td>
[nametagSceneUI](./server.playerentity.nametagsceneui.md)
</td><td>
`readonly`
</td><td>
[SceneUI](./server.sceneui.md)
</td><td>
The SceneUI instance for the player entity's nametag.
\*\*Category:\*\* Entities
</td></tr>
<tr><td>
[player](./server.playerentity.player.md)
</td><td>
`readonly`
</td><td>
[Player](./server.player.md)
</td><td>
The player this entity is assigned to and controlled by.
\*\*Category:\*\* Entities
</td></tr>
</tbody></table>
## Methods
<table><thead><tr><th>
Method
</th><th>
Modifiers
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
[setTickWithPlayerInputEnabled(enabled)](./server.playerentity.settickwithplayerinputenabled.md)
</td><td>
</td><td>
Enables or disables `tickWithPlayerInput()` during the entity's tick.
Use for: temporarily disabling player control (cutscenes, menus, stuns).
</td></tr>
</tbody></table>