hytopia
Version:
The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.
135 lines (62 loc) • 2.8 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [server](./server.md) > [BaseEntityController](./server.baseentitycontroller.md)
## BaseEntityController class
A base class for entity controller implementations.
When to use: implementing custom entity behavior and movement logic. Do NOT use for: one-off entity changes; prefer direct entity APIs.
**Signature:**
```typescript
export default abstract class BaseEntityController extends EventRouter
```
**Extends:** [EventRouter](./server.eventrouter.md)
## Remarks
Controllers are typically one instance per entity, but can be shared across entities if you manage state carefully.
<h2>Lifecycle</h2>
1) `attach()` — called during `Entity` construction when a controller is provided. 2) `spawn()` — called after the entity is added to the physics simulation. 3) `tickWithPlayerInput()` — called each world tick for `PlayerEntity` before `tick()`<!-- -->. 4) `tick()` — called each world tick before physics stepping. 5) `detach()` → `despawn()` — called during `Entity.despawn`<!-- -->.
<h2>Events</h2>
This class is an EventRouter, and instances of it emit events with payloads listed under `BaseEntityControllerEventPayloads`<!-- -->.
\*\*Category:\*\* Controllers
## Methods
<table><thead><tr><th>
Method
</th><th>
Modifiers
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
[attach(entity)](./server.baseentitycontroller.attach.md)
</td><td>
</td><td>
Override this method to handle the attachment of an entity to your entity controller.
</td></tr>
<tr><td>
[despawn(entity)](./server.baseentitycontroller.despawn.md)
</td><td>
</td><td>
Override this method to handle the despawn of an entity from your entity controller.
</td></tr>
<tr><td>
[detach(entity)](./server.baseentitycontroller.detach.md)
</td><td>
</td><td>
Override this method to handle the detachment of an entity from your entity controller.
</td></tr>
<tr><td>
[spawn(entity)](./server.baseentitycontroller.spawn.md)
</td><td>
</td><td>
Override this method to handle the spawning of an entity to your entity controller.
</td></tr>
<tr><td>
[tick(entity, deltaTimeMs)](./server.baseentitycontroller.tick.md)
</td><td>
</td><td>
Override this method to handle entity movements based on your entity controller.
</td></tr>
<tr><td>
[tickWithPlayerInput(entity, input, cameraOrientation, deltaTimeMs)](./server.baseentitycontroller.tickwithplayerinput.md)
</td><td>
</td><td>
Override this method to handle entity movements based on player input for your entity controller.
</td></tr>
</tbody></table>