A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
docs(ai): a melee enemy without writing one
esengineac21e8f91731
diff --git a/desktop b/desktopindex a88ed09bd..e79bfac0a 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit a88ed09bd8b905a9693d42726f8179b22fcfa332+Subproject commit e79bfac0ae707489ac508e47b0a5f396ee1aeba5diff --git a/docs/astro/src/content/docs/gameplay/ai/overview.mdx b/docs/astro/src/content/docs/gameplay/ai/overview.mdxindex d59190fb9..407706de2 100644--- a/docs/astro/src/content/docs/gameplay/ai/overview.mdx+++ b/docs/astro/src/content/docs/gameplay/ai/overview.mdx@@ -186,6 +186,57 @@ unlocks when it completes, and R replays it — with zero registered actions.<LinkCard title="Below the components" href="/docs/gameplay/ai/advanced/" description="Pathfinding by hand, perception internals, and bare-App wiring." /></CardGrid>+## A melee enemy without writing one++`Hunter` is the concrete twin of `ThirdPersonController`: that one turns INPUT+into a request, this one turns PERCEPTION into one. Everything downstream is the+same machinery a player goes through — the route is navigation's, the movement is+the character controller's, the speed the animator hears is the one the world+allowed, and a swing is an animator trigger that comes back through the same+`MeleeAttack`. An attacker being a program rather than a person changes nothing+about the mechanism.++```typescript+enemy.add(Perceiver, { range: 420 });+enemy.add(Perception, {});+enemy.add(NavAgent, { speed: 320, radius: 30, arriveRadius: 40 });+enemy.add(Hunter, { attackRange: 100, attackInterval: 1.6 });+enemy.add(MeleeAttack, { radius: 110, damage: 20, anchor: swordSocket });+enemy.add(Health, { current: 50, max: 50 });+```++| Field | What it does |+|---|---|+| `attackRange` | Ground-plane distance it closes to before it swings. |+| `attackInterval` | Seconds between swings. |+| `rotationSpeed` | How fast it turns to face, degrees/second. |+| `idleThreshold` | Speed under which the animator is told it is standing still. |+| `state` | Engine-written: `idle` / `chase` / `attack` / `dead`. |+| `cooldown` | Engine-written: seconds until it may swing again. |++Four states, and no authoring surface — this is a concrete enemy, not a+framework. The FSM and behaviour-tree runtimes above are how a GAME declares its+own; reach for those the moment two enemies want to behave differently.++<Aside>+ The state is recomputed every frame rather than latched, so a target that steps+ away mid-swing is chased again instead of being swung at. Which way it looks is+ two questions, not one: while chasing it faces where it actually WENT, and+ while swinging it faces the target — a swing aimed down the last of a drift+ lands beside what it was aimed at.+</Aside>++<Aside type="caution">+ Navigation SKIPS an agent with no destination, so clearing the target is not+ stopping — the velocity it last wrote would carry the body on. `Hunter` zeroes+ it as well, and anything else that stops an agent must do the same.+</Aside>++`Health` reaching zero is what makes it `dead`: navigation stops, the animator is+told it is standing still, and no trigger is set. A swing already in the air when+its owner went down lands on nobody — that half is `MeleeAttack`'s, so it is not+left to whoever remembers to switch something off.+## Putting it togetherThe [`enemy-ai` example](https://github.com/esengine/estella/tree/master/examples/enemy-ai)diff --git a/docs/astro/src/content/docs/zh-cn/gameplay/ai/overview.mdx b/docs/astro/src/content/docs/zh-cn/gameplay/ai/overview.mdxindex e1c06b576..9157930b9 100644--- a/docs/astro/src/content/docs/zh-cn/gameplay/ai/overview.mdx+++ b/docs/astro/src/content/docs/zh-cn/gameplay/ai/overview.mdx@@ -166,6 +166,49 @@ registerFsm('intro', {<LinkCard title="组件层之下" href="/docs/zh-cn/gameplay/ai/advanced/" description="手动寻路、感知内幕,以及裸 App 接线。" /></CardGrid>+## 不用写代码的近战敌人++`Hunter` 是 `ThirdPersonController` 的具体孪生:那个把**输入**变成请求,这个把+**感知**变成请求。往下的一切都是玩家走的同一套机器——路线是导航的,移动是角色控制器的,+动画器听到的速度是世界允许的那个,而一次挥击是一个动画器触发器、并且从同一个+`MeleeAttack` 回来。攻击者是程序而不是人,不改变任何机制。++```typescript+enemy.add(Perceiver, { range: 420 });+enemy.add(Perception, {});+enemy.add(NavAgent, { speed: 320, radius: 30, arriveRadius: 40 });+enemy.add(Hunter, { attackRange: 100, attackInterval: 1.6 });+enemy.add(MeleeAttack, { radius: 110, damage: 20, anchor: swordSocket });+enemy.add(Health, { current: 50, max: 50 });+```++| 字段 | 作用 |+|---|---|+| `attackRange` | 地平面上靠近到多远才挥击。 |+| `attackInterval` | 两次挥击之间的秒数。 |+| `rotationSpeed` | 转身速度,度/秒。 |+| `idleThreshold` | 低于这个速度就告诉动画器它站着不动。 |+| `state` | 引擎写入:`idle` / `chase` / `attack` / `dead`。 |+| `cooldown` | 引擎写入:还有多少秒才能再挥。 |++四个状态,没有任何创作面——这是一个具体的敌人,不是框架。上面的 FSM 与行为树运行时才是+**游戏**声明自己 AI 的地方;等到第二种敌人想有不同行为时再去拿它们。++<Aside>+ 状态每帧重算而不是锁存,所以在挥击中途走开的目标会被重新追,而不是被对着空气挥。+ 「朝哪看」是两个问题不是一个:追击时朝它**实际走**的方向,挥击时朝目标——+ 一刀顺着残余漂移挥出去,会落在它本来瞄的东西旁边。+</Aside>++<Aside type="caution">+ 导航会**跳过**没有目的地的 agent,所以清掉目标不等于停下——它上一次写的速度会带着身体+ 继续走。`Hunter` 会把速度一并清零,任何别的「让 agent 停下」的代码也必须这么做。+</Aside>++`Health` 归零就是 `dead`:导航停止,动画器被告知站着不动,不再设触发器。主人倒下时+已经挥在空中的那一刀不会打到任何人——那一半是 `MeleeAttack` 的责任,所以不用指望+谁记得去关掉什么开关。+## 组合起来[`enemy-ai` 示例](https://github.com/esengine/estella/tree/master/examples/enemy-ai)diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.jsonindex fc9acef0b..af8a4d01c 100644--- a/docs/astro/src/data/apiStability.generated.json+++ b/docs/astro/src/data/apiStability.generated.json@@ -3,10 +3,10 @@"counts": {"public": 113,"beta": 91,- "experimental": 1760,+ "experimental": 1766,"deprecated": 3},- "total": 1964,+ "total": 1970,"subsystems": [{"id": "ecs",diff --git a/docs/astro/src/data/componentDocs.ts b/docs/astro/src/data/componentDocs.tsindex 8ce3789df..1e09c3432 100644--- a/docs/astro/src/data/componentDocs.ts+++ b/docs/astro/src/data/componentDocs.ts@@ -118,6 +118,7 @@ export const COMPONENT_DOCS: Record<string, ComponentDoc> = {ThirdPersonController: { category: 'physics', summary: 'Turns input into a movement request for a CharacterController3D, and reports what the character actually did to its Animator.', doc: 'gameplay/physics-3d', anchor: 'third-person', anchorZh: '第三人称' },ThirdPersonCamera: { category: 'physics', summary: 'An eye that orbits a target under pointer control and pulls in when something solid stands between.', doc: 'gameplay/physics-3d', anchor: 'third-person', anchorZh: '第三人称' },MeleeAttack: { category: 'physics', summary: 'A swing whose timing is the animation’s and whose reach is the physics world’s: a `hit` beat asks what is around an animated anchor, and gameplay decides who may be hurt.', doc: 'gameplay/physics-3d', anchor: 'melee-combat', anchorZh: '近战' },+ Hunter: { category: 'physics', summary: 'A character that hunts what it perceives: it asks navigation for a route, the character controller for the movement, and the animator for a swing — the concrete twin of ThirdPersonController.', doc: 'gameplay/ai/overview', anchor: 'a-melee-enemy-without-writing-one', anchorZh: '不用写代码的近战敌人' },Health: { category: 'physics', summary: 'What something has left, and what makes it damageable at all — written only by the system that answers the Damage bus.', doc: 'gameplay/physics-3d', anchor: 'melee-combat', anchorZh: '近战' },PointJoint3D: { category: 'physics', summary: 'Holds two 3D bodies at a shared point, free to turn on all three axes — a chain link, a ragdoll limb.', doc: 'gameplay/physics-3d', anchor: 'joints', anchorZh: '关节' },HingeJoint3D: { category: 'physics', summary: 'One axis of rotation between two 3D bodies — a door or a driven wheel, with optional limits and a motor.', doc: 'gameplay/physics-3d', anchor: 'joints', anchorZh: '关节' },diff --git a/docs/astro/src/data/components.generated.json b/docs/astro/src/data/components.generated.jsonindex 9cd0c2425..5d4ed1124 100644--- a/docs/astro/src/data/components.generated.json+++ b/docs/astro/src/data/components.generated.json@@ -1754,6 +1754,64 @@"angle"]},+ {+ "name": "Hunter",+ "source": "ts",+ "fields": [+ {+ "key": "attackRange",+ "type": "number",+ "default": "110",+ "doc": "How close it gets before it swings.",+ "range": "≥ 0"+ },+ {+ "key": "attackInterval",+ "type": "number",+ "default": "1.6",+ "range": "≥ 0"+ },+ {+ "key": "rotationSpeed",+ "type": "number",+ "default": "540",+ "range": "≥ 0"+ },+ {+ "key": "idleThreshold",+ "type": "number",+ "default": "8",+ "range": "≥ 0, step 0.05",+ "advanced": true+ },+ {+ "key": "enabled",+ "type": "boolean",+ "default": "true"+ },+ {+ "key": "state",+ "type": "string",+ "default": "\"idle\"",+ "readonly": true,+ "advanced": true+ },+ {+ "key": "cooldown",+ "type": "number",+ "default": "0",+ "readonly": true,+ "advanced": true+ }+ ],+ "animatable": [+ "attackRange",+ "attackInterval",+ "rotationSpeed",+ "idleThreshold",+ "cooldown"+ ]+ },{"name": "Interactable","source": "cpp",