Skip to main content

Overview

Entities are the core game objects in Hyperscape. Every player, mob, item, and resource is an Entity with 3D representation, networking, physics, and component-based functionality.

Entity Hierarchy

Key Features

From packages/shared/src/entities/Entity.ts:

Entity Class

Lifecycle Methods

Component Management

Default Components

Every entity automatically gets these components:

Network Synchronization

Health and Damage

Position and Transform

PlayerEntity

The player entity extends CombatantEntity with player-specific features:

Player Components

MobEntity

Mob entities represent hostile NPCs with AI behavior:

Events

Entities can emit and listen to events:

Best Practices

  1. Use components for data - Don’t add properties directly to entities
  2. Check component existence - Always null-check getComponent() results
  3. Mark network dirty - Call markNetworkDirty() after state changes
  4. Override lifecycle methods - Implement createMesh(), onInit(), onInteract() in subclasses
  5. Clean up properly - Override destroy() and call super.destroy()