Core Concepts

Entity System

The hierarchical entity architecture for all game objects.

The entity system is a class hierarchy where each level adds more capabilities. Choose the appropriate base class for your entity.

GameObject
  └── Actor
        ├── Entity3D
        └── LivingActor

GameObject

The base class for everything in the world.

import { GameObject } from '@mavonengine/core'

class MyObject extends GameObject {
  update(delta: number): void {
    // Called every tick/frame
  }
}

Properties

PropertyTypeDescription
positionVector3World position
rotationVector3Euler rotation
scaleVector3Scale
colliderMeshMesh | undefinedOptional physics collider mesh
garbageCollectbooleanSet to true to mark for deletion

Methods

MethodDescription
abstract update(delta)Called every tick. Must be implemented.
serialize()Returns a plain object for network/state serialization
destroy()Cleanup resources

Actor

Extends GameObject with a pushdown automaton state machine.

import { Actor } from '@mavonengine/core'

class MyActor extends Actor {
  // State machine is managed automatically
}

Properties

PropertyTypeDescription
stateEntityState[]Stack of active states
stateHashstringHash of the serialized state stack

The update(delta) method on Actor automatically delegates to the top state on the stack.

See State Machine for full details.

Entity3D

Extends Actor with Three.js model support and animations.

import { Entity3D } from '@mavonengine/core'
import type { GLTF } from 'three/examples/jsm/loaders/GLTFLoader'

class MyCharacter extends Entity3D {
  constructor(gltf: GLTF) {
    super()
    this.initModel(gltf)
  }
}

Properties

PropertyTypeDescription
instanceGroupThree.js object group (the model)
animationMixerAnimationMixer | undefinedThree.js animation mixer
animationsMapMap<string, AnimationAction>Named animation actions
activeActionAnimationAction | undefinedCurrently playing animation

Methods

MethodDescription
initModel(gltf)Initialize from a loaded GLTF asset
fadeToAction(name, duration)Smoothly transition to a named animation
destroy()Removes model from scene and disposes geometry

LivingActor

Abstract extension of Actor for entities that can take damage and have health.

import { LivingActor } from '@mavonengine/core'

class MyEnemy extends LivingActor {
  health = 100
  maxHealth = 100

  isDead(): void { /* ... */ }
  takeDamage(amount: number): void { /* ... */ }
  heal(amount: number): void { /* ... */ }
}

Abstract members

MemberDescription
healthCurrent health value
maxHealthMaximum health value
isDead()Called when health reaches zero
takeDamage(amount)Apply damage
heal(amount)Restore health

Implements the Damageable interface.