Skip to main content

Tile Movement System

Hyperscape uses a discrete tile-based movement system inspired by RuneScape. The world is divided into tiles, and entities move one tile at a time in sync with server ticks.
The tile system lives in packages/shared/src/systems/shared/movement/TileSystem.ts.

Core Constants

Hyperscape uses 2x OSRS speed for a snappier modern feel while keeping the tick-based system. OSRS uses 1 tile/tick walk, 2 tiles/tick run.

Agility XP from Movement

Movement grants Agility XP at a rate of 1 XP per 2 tiles traveled:
  • Walking: 2 tiles/tick = ~100 XP/minute
  • Running: 4 tiles/tick = ~200 XP/minute
  • XP granted in batches of 50 XP every 100 tiles (prevents visual spam)
  • Death penalty: Accumulated tile progress is lost (max ~50 XP worth)
Agility XP is tracked server-side in TileMovementManager and granted via the SKILLS_XP_GAINED event. See Skills System for details on agility’s stamina regeneration bonus.

Tile Coordinates

Tiles use integer coordinates on the X-Z plane. Height (Y) comes from terrain.

World ↔ Tile Conversion


Movement State

Each entity with movement has a TileMovementState:

Previous Tile (OSRS Follow Mechanic)


Distance Functions

Manhattan Distance

Used for simple distance checks:

Chebyshev Distance

The actual “tile distance” for diagonal movement:

Adjacency Functions

8-Direction Adjacency

Cardinal-Only Adjacency


Combat Positioning

Melee Range

OSRS Accuracy: Standard melee (range 1) requires cardinal adjacency only. You cannot attack diagonally without a halberd (range 2).

Best Combat Tile


NPC Step-Out

When an NPC is on the same tile as its target, it must step out before attacking.

Resource Interaction

Multi-Tile Resources

Large resources (like trees) span multiple tiles. Players can interact from any adjacent tile.

Cardinal-Only Interaction

For consistent face direction during resource gathering:

Collision System

Hyperscape uses a unified CollisionMatrix for OSRS-accurate tile-based collision. The system handles static objects (trees, rocks, stations), entities (players, NPCs), and terrain (water, slopes).

CollisionMatrix Architecture

The collision system uses zone-based storage for optimal memory and performance:
Zone-Based Storage:
  • World divided into 8×8 tile zones
  • Each zone = Int32Array[64] = 256 bytes
  • 1000×1000 tile world = ~4MB memory
  • Lazy allocation (zones created on first write)

Collision Flags

Tiles use bitmask flags for efficient collision queries:

Usage Examples

Multi-Tile Footprints

Stations and large resources can occupy multiple tiles:
Footprints are centered on the entity position, not corner-based. A 2×2 station at (10,10) occupies tiles (9,9) through (10,10).

Entity Occupancy

The EntityOccupancyMap tracks which tiles are occupied by entities and delegates to CollisionMatrix for unified storage:
Entity moves are atomic - old tiles are freed and new tiles occupied in a single operation. Delta optimization ensures only changed tiles are updated.

Zero-Allocation Helpers

For performance in hot paths, use pre-allocated buffers:

Agility XP Tracking

The movement system tracks tiles traveled for Agility skill XP:
XP Batching Design:
  • Prevents visual spam (XP drop every ~15 seconds running, ~30 seconds walking)
  • Preserves partial progress between batches
  • Death resets tile counter (small penalty)
  • Logout/disconnect clears counter (max ~50 XP lost)
Agility XP is granted automatically as players move. Both walking and running count toward XP at the same rate (1 XP per 2 tiles).

Stamina System

Stamina is a client-side mechanic that affects running ability. It’s influenced by both Agility level and inventory weight.

Base Stamina Rates

Weight-Based Drain

Inventory weight increases stamina drain while running:
Weight Impact:

Agility-Based Regeneration

Agility level increases stamina regeneration:
Agility Impact:

Weight Synchronization

Player weight is calculated server-side and synced to the client:
Weight is server-authoritative to prevent client-side manipulation. The Equipment Panel displays the server-synced weight value.

Client Interpolation

The client smoothly interpolates entity positions between server ticks.

Terrain Flattening

Stations and structures can flatten terrain underneath for level building surfaces using the Flat Zone System.

Flat Zone Interface

TerrainSystem API

How It Works

  1. Height Calculation Priority: Flat zones checked before procedural terrain
  2. Core Flat Area: Inside the zone, terrain returns exact height value
  3. Blend Area: Within blendRadius of zone edge, smoothstep interpolation blends to procedural terrain
  4. Spatial Indexing: Terrain tiles (100m) used for O(1) lookup
  5. Manifest-Driven: Stations with flattenGround: true automatically create flat zones
Blend Formula:
Flat zones are loaded from world-areas.json during terrain initialization. Station footprints are calculated from model bounds × scale.