Migration Guide: v2.x to v3.0
This guide helps you migrate to Hyperscape v3.0, which introduces mob magic and ranged attacks.Overview
Version 3.0 adds support for mob projectile attacks (magic and ranged). All changes are backward compatible—existing mobs continue to work without modification.What’s New
Mob Attack Types
Mobs can now use three attack types:- Melee (default) - Close-range combat
- Ranged (new) - Bow and arrow attacks
- Magic (new) - Spell casting
New NPC Configuration Fields
Breaking Changes
None. All changes are backward compatible.Deprecations
None. All existing APIs remain unchanged.Migration Steps
Step 1: Update Dependencies
Step 2: Review Existing Mobs (Optional)
All existing mobs default toattackType: "melee" and continue to work without changes.
No action required unless you want to convert mobs to ranged/magic.
Step 3: Add Ranged/Magic Mobs (Optional)
To convert an existing mob to ranged or magic: Before (v2.x):Step 4: Test Your Changes
API Changes
New Functions
prepareMobAttack()
Shared utility for mob projectile attack validation.MagicAttackHandler and RangedAttackHandler to validate mob attacks.
getMobAttackType()
Type guard for safely reading mob attack type.Modified Functions
MagicAttackHandler.handle()
Now supports mob attackers:RangedAttackHandler.handle()
Now supports mob attackers:CombatSystem.handleAttack()
Now requiresattackType parameter:
attackType. The CombatTickProcessor automatically resolves this from combat state.
Event Changes
COMBAT_MOB_NPC_ATTACK
Added Fields:COMBAT_PROJECTILE_LAUNCHED
Added Fields:Configuration Changes
Combat Constants
New Constants:Code Examples
Creating a Magic Mob
Creating a Ranged Mob
Handling Mob Attacks in Custom Code
Performance Notes
Weapon Model Caching
Weapon GLB models are cached statically and shared across all mobs:- Reduces network requests
- Shares geometry/material buffers
- Concurrent loads deduplicated
- Cache cleared on world teardown
- Individual mobs only remove from scene graph (no disposal)
Pre-Allocated Damage Params
Attack handlers reuse pre-allocated parameter objects:- Tick loop is single-threaded
- Mob paths are synchronous
- Player paths claim cooldown before any
await
await between params mutation and damage calculation.
Troubleshooting
Mob Not Using Ranged/Magic
Symptoms:- Mob uses melee animation instead of ranged/magic
- No projectile appears
- Verify
attackTypeis set in NPC combat config - For magic: Verify
spellIdis specified - For ranged: Verify
arrowIdis specified - Check console for warnings:
"Mob X has no spellId configured""Mob X has no arrowId configured"
Weapon Not Showing on Mob
Symptoms:- Mob attacks correctly but no weapon visible
- Verify
heldWeaponModelusesasset://prefix - Verify weapon GLB exists in assets directory
- Check browser console for GLTF load errors
- Ensure CDN is running (
bun run cdn:up)
Wrong Projectile Visual
Symptoms:- Projectile appears but wrong color/type
- For magic: Verify
spellIdmatches spell data- Check
packages/shared/src/data/combat-spells.ts
- Check
- For ranged: Verify
arrowIdmatches ammunition data- Check
packages/shared/src/data/ammunition.ts
- Check
Rollback Instructions
If you need to rollback to v2.x:attackType: "ranged" or attackType: "magic" will fall back to melee.
Support
For questions or issues:- GitHub Issues: https://github.com/HyperscapeAI/hyperscape/issues
- Discord: https://discord.gg/hyperscape
Migration Guide for Hyperscape v3.0