build-threejs-enemy-systems

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Build Three.js Enemy Systems

构建Three.js敌人系统

Make each enemy a portable authored definition consumed by shared runtime systems. Keep AI choice, combat resolution, rendering, and feedback as separate consumers of the same stable contract.
将每个敌人设计为由共享运行时系统调用的可移植创作定义。让AI决策、战斗结算、渲染与反馈作为同一稳定协议的独立调用方。

Separate content from runtime state

将内容与运行时状态分离

  • Put stable IDs, role/tags, base stats, presentation spec, move IDs, AI hints, feedback hook IDs, rewards, and variant data in immutable authored definitions.
  • Put instance ID, transform, health/posture, target, current move and phase clock, cooldowns, statuses, pathing, visibility, and LOD state in runtime instances.
  • Reference definitions by ID. Reject duplicate IDs, missing references, invalid ranges, or impossible timing during content validation.
  • Never mutate authored definitions, store live timers in content, or duplicate the combat clock across AI, animation, and rendering.
  • 把稳定ID、角色/标签、基础属性、表现规格、动作ID、AI提示、反馈钩子ID、奖励与变体数据存入不可变的创作定义中。
  • 把实例ID、变换信息、生命值/姿态、目标、当前动作与阶段时钟、冷却时间、状态、路径、可见性和LOD状态存入运行时实例中。
  • 通过ID引用定义。在内容验证阶段拒绝重复ID、缺失引用、无效范围或不合理的时间设置。
  • 绝不要修改创作定义,不要在内容中存储实时计时器,也不要在AI、动画与渲染模块中重复战斗时钟。

Normalize presentation contracts

统一表现协议

Define these fields before integrating a model:
  • source or factory ID, provenance, coordinate system, forward axis, and meters-per-unit;
  • root pivot at ground contact, normalized scale, facing offset, and visual height;
  • simple movement collider plus named hurtboxes, independent of render geometry;
  • stable sockets for contact origins, weapons, projectiles, VFX, audio, UI markers, and targeting;
  • rig and semantic clip map for idle, locomotion, moves, reactions, and death;
  • LOD tiers with hysteresis, animation/update policy, and unchanged gameplay colliders.
Normalize at the asset boundary. Do not scatter scale fixes, pivot offsets, raw clip names, or compensating rotations through gameplay code.
在集成模型前定义以下字段:
  • 源或工厂ID、来源、坐标系、前向轴与单位米数;
  • 位于地面接触点的根轴心、归一化缩放、朝向偏移与视觉高度;
  • 独立于渲染几何体的简单移动碰撞体及命名受击盒;
  • 用于碰撞原点、武器、投射物、VFX、音频、UI标记与目标锁定的稳定插槽;
  • 对应 idle、移动、动作、反应与死亡状态的绑定结构和语义动画片段映射;
  • 带有滞后机制、动画/更新策略且不改变游戏玩法碰撞体的LOD层级。
在资产边界处完成统一。不要在游戏玩法代码中分散缩放修正、轴心偏移、原始片段名称或补偿旋转逻辑。

Define moves as data

将动作定义为数据

For every move, define:
  • stable ID, AI tags, eligibility range/angle/line-of-sight, weight, and state prerequisites;
  • startup and telegraph, one or more active windows, recovery, cooldown, and minimum commitment;
  • movement, facing, cancellation, armor, interrupt, stagger, and phase rules;
  • contact shape/socket, damage, posture, knockback, status, and per-target hit limits;
  • semantic animation, VFX, and audio hook IDs with cleanup rules.
Let AI select only legal move IDs; let the combat system own timing and outcomes. Resolve damage from authoritative collision/contact events using stable action and target identifiers. Apply each contact once, then drive animation, VFX, audio, and UI from the resolved event.
为每个动作定义:
  • 稳定ID、AI标签、适用范围/角度/视线、权重与状态前提;
  • 前摇与预警、一个或多个生效窗口、后摇、冷却时间与最小持续时间;
  • 移动、朝向、取消、霸体、打断、 stagger 与阶段规则;
  • 碰撞形状/插槽、伤害、姿态、击退、状态效果与单目标命中限制;
  • 带有清理规则的语义动画、VFX与音频钩子ID。
让AI仅选择合法的动作ID;让战斗系统掌控时机与结果。使用稳定的动作和目标标识符,通过权威碰撞/接触事件结算伤害。每个碰撞仅生效一次,然后根据结算事件驱动动画、VFX、音频与UI。

Provide an honest fallback

提供可靠的回退方案

When a production model is unavailable, use a deliberate placeholder that preserves footprint, height, pivot, collider, sockets, facing, move timing, and state readability. Log the fallback once and keep it visually unmistakable. Never silently substitute a mismatched asset or call placeholder visuals production-ready.
当生产模型不可用时,使用能保留占用空间、高度、轴心、碰撞体、插槽、朝向、动作时机与状态可读性的明确占位符。仅记录一次回退信息,并确保其视觉辨识度极高。绝不要静默替换不匹配的资产,也不要将占位符视觉效果当作生产可用版本。

Add a new enemy

添加新敌人

  1. Existing archetype and moves fit? Configure a new definition; do not add runtime branches.
  2. A new behavior is essential? Add the smallest reusable move, hook, or AI tag before adding a new subsystem.
  3. Model ready? Normalize it to the shared presentation contract; otherwise use the honest fallback.
  4. Content complete? Validate references, timing, contact, cooldown, recovery, interrupts, and feedback hooks.
  5. Proof ready? Add deterministic fixtures and automated tests, then run desktop and mobile playthroughs.
  1. 现有原型与动作是否适用? 配置新的定义即可;不要添加运行时分支。
  2. 是否需要新增行为? 在添加新子系统前,先添加最小化的可复用动作、钩子或AI标签。
  3. 模型是否就绪? 将其统一到共享表现协议中;否则使用可靠的回退方案。
  4. 内容是否完成? 验证引用、时机、碰撞、冷却、后摇、打断与反馈钩子。
  5. 是否准备好验证? 添加确定性测试装置与自动化测试,然后在桌面和移动端进行游玩测试。

Prove the system

验证系统

  • Create deterministic fixtures for spawn, each move phase, wrong range/direction, obstruction, interrupt, stagger, death/reset, missing-model fallback, LOD transitions, and multiple instances sharing one definition.
  • Test content uniqueness and references, active-window boundaries, cooldown/recovery, per-target hit deduplication, lifecycle cleanup, and pause/frame-step behavior.
  • Play a representative encounter in the repository-approved browser. Confirm telegraphs, contact, state, animation, VFX/audio, targetability, and rewards agree.
  • Verify desktop and mobile camera distance, touch controls, reduced motion, console health, frame time, draw calls, memory stability, and crowded-scene LOD behavior. Report baseline failures separately.
  • 为生成、每个动作阶段、错误范围/方向、障碍物、打断、 stagger、死亡/重置、缺失模型回退、LOD切换以及多个实例共享一个定义的场景创建确定性测试装置。
  • 测试内容唯一性与引用、生效窗口边界、冷却/后摇、单目标去重命中、生命周期清理以及暂停/逐帧步进行为。
  • 在仓库认可的浏览器中进行代表性战斗测试。确认预警、碰撞、状态、动画、VFX/音频、可锁定性与奖励符合预期。
  • 验证桌面和移动端的相机距离、触控控制、简化动画、控制台健康状态、帧时间、绘制调用、内存稳定性以及拥挤场景下的LOD行为。单独报告基线故障。