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
test(gameplay): the swing, claimed end to end in the packaged game
esengine0f50ffb3aea7
diff --git a/examples/third-person-3d/assets/models/attack.estimeline b/examples/third-person-3d/assets/models/attack.estimelinenew file mode 100644index 000000000..5e4a2096d--- /dev/null+++ b/examples/third-person-3d/assets/models/attack.estimeline@@ -0,0 +1,186 @@+{+ "version": "1.2",+ "type": "timeline",+ "duration": 1,+ "wrapMode": "once",+ "tracks": [+ {+ "type": "property",+ "name": "Root",+ "childPath": "",+ "component": "Transform",+ "channels": [+ {+ "property": "position.z",+ "keyframes": [+ {+ "time": 0,+ "value": 0,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ },+ {+ "time": 0.5,+ "value": -70,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ },+ {+ "time": 1,+ "value": -70,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ }+ ]+ }+ ]+ },+ {+ "type": "property",+ "name": "Bone1",+ "childPath": "Bone1",+ "component": "Transform",+ "channels": [+ {+ "property": "rotation.x",+ "keyframes": [+ {+ "time": 0,+ "value": 0,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ },+ {+ "time": 1,+ "value": 0,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ }+ ]+ },+ {+ "property": "rotation.y",+ "keyframes": [+ {+ "time": 0,+ "value": 0,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ },+ {+ "time": 0.35,+ "value": 0,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ },+ {+ "time": 0.7,+ "value": 0.8191520442889918,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ },+ {+ "time": 1,+ "value": 0,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ }+ ]+ },+ {+ "property": "rotation.z",+ "keyframes": [+ {+ "time": 0,+ "value": 0,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ },+ {+ "time": 1,+ "value": 0,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ }+ ]+ },+ {+ "property": "rotation.w",+ "keyframes": [+ {+ "time": 0,+ "value": 1,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ },+ {+ "time": 0.35,+ "value": 1,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ },+ {+ "time": 0.7,+ "value": 0.573576436351046,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ },+ {+ "time": 1,+ "value": 1,+ "inTangent": 0,+ "outTangent": 0,+ "interpolation": "linear"+ }+ ]+ }+ ]+ },+ {+ "type": "customEvent",+ "name": "Beats",+ "childPath": "",+ "events": [+ {+ "time": 0,+ "name": "attack-start",+ "payload": {}+ },+ {+ "time": 0.18,+ "name": "windup",+ "payload": {}+ },+ {+ "time": 0.45,+ "name": "hit",+ "payload": {}+ },+ {+ "time": 0.6,+ "name": "hit",+ "payload": {}+ },+ {+ "time": 0.9,+ "name": "attack-end",+ "payload": {}+ }+ ]+ }+ ]+}diff --git a/examples/third-person-3d/assets/models/attack.estimeline.meta b/examples/third-person-3d/assets/models/attack.estimeline.metanew file mode 100644index 000000000..f86917b75--- /dev/null+++ b/examples/third-person-3d/assets/models/attack.estimeline.meta@@ -0,0 +1,6 @@+{+ "uuid": "73dd13fc-2888-4111-b648-7283bc7a665c",+ "version": "2.0",+ "type": "animation",+ "importer": {}+}diff --git a/examples/third-person-3d/assets/models/locomotion.esanimator b/examples/third-person-3d/assets/models/locomotion.esanimatorindex bfeee94df..d3d140974 100644--- a/examples/third-person-3d/assets/models/locomotion.esanimator+++ b/examples/third-person-3d/assets/models/locomotion.esanimator@@ -13,6 +13,10 @@{"name": "dodge","type": "trigger"+ },+ {+ "name": "attack",+ "type": "trigger"}],"initialState": "Idle",@@ -92,6 +96,23 @@"duration": 0.12}]+ },+ {+ "name": "Attack1",+ "motion": {+ "kind": "timeline",+ "clip": "attack.estimeline",+ "loop": false+ },+ "rootMotion": true,+ "transitions": [+ {+ "to": "Idle",+ "conditions": [],+ "hasExitTime": true,+ "duration": 0.15+ }+ ]}],"anyStateTransitions": [@@ -104,6 +125,16 @@}],"duration": 0.08+ },+ {+ "to": "Attack1",+ "conditions": [+ {+ "param": "attack",+ "op": "trigger"+ }+ ],+ "duration": 0.08}]}diff --git a/examples/third-person-3d/assets/scenes/gym.esscene b/examples/third-person-3d/assets/scenes/gym.essceneindex b67be31fd..e9817e188 100644--- a/examples/third-person-3d/assets/scenes/gym.esscene+++ b/examples/third-person-3d/assets/scenes/gym.esscene@@ -343,6 +343,21 @@"data": {"enabled": true}+ },+ {+ "type": "MeleeAttack",+ "data": {+ "radius": 70,+ "damage": 25,+ "anchor": 14+ }+ },+ {+ "type": "Health",+ "data": {+ "current": 100,+ "max": 100+ }}]},@@ -369,7 +384,9 @@"id": 7,"name": "Bone1","parent": 5,- "children": [],+ "children": [+ 14+ ],"visible": true,"components": [{@@ -672,6 +689,269 @@}}]+ },+ {+ "id": 14,+ "name": "HitAnchor",+ "parent": 7,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 80,+ "y": 0,+ "z": 0+ }+ }+ }+ ]+ },+ {+ "id": 15,+ "name": "DummyA",+ "parent": null,+ "children": [+ 16+ ],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 129,+ "y": 60,+ "z": 17+ }+ }+ },+ {+ "type": "RigidBody3D",+ "data": {+ "bodyType": 0+ }+ },+ {+ "type": "BoxCollider3D",+ "data": {+ "halfExtents": {+ "x": 25,+ "y": 60,+ "z": 25+ },+ "isSensor": true+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "color": {+ "r": 0.78,+ "g": 0.35,+ "b": 0.32,+ "a": 1+ }+ }+ },+ {+ "type": "Health",+ "data": {+ "current": 100,+ "max": 100+ }+ }+ ]+ },+ {+ "id": 16,+ "name": "HitSparkA",+ "parent": 15,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "ParticleEmitter",+ "data": {+ "rate": 0,+ "burstCount": 18,+ "burstInterval": 0,+ "duration": 0.05,+ "looping": false,+ "playOnStart": false,+ "maxParticles": 72,+ "lifetimeMin": 0.5,+ "lifetimeMax": 0.9,+ "shape": 4,+ "shapeRadius": 12,+ "speedMin": 90,+ "speedMax": 240,+ "startSizeMin": 8,+ "startSizeMax": 14,+ "endSizeMin": 0,+ "endSizeMax": 4,+ "startColor": {+ "r": 1.0,+ "g": 0.82,+ "b": 0.45,+ "a": 1.0+ },+ "endColor": {+ "r": 0.95,+ "g": 0.32,+ "b": 0.2,+ "a": 0.0+ },+ "gravity": {+ "x": 0,+ "y": -320,+ "z": 0+ },+ "damping": 2.0,+ "blendMode": 1,+ "layer": 0,+ "simulationSpace": 0+ }+ }+ ]+ },+ {+ "id": 17,+ "name": "DummyB",+ "parent": null,+ "children": [+ 18+ ],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -129,+ "y": 60,+ "z": 17+ }+ }+ },+ {+ "type": "RigidBody3D",+ "data": {+ "bodyType": 0+ }+ },+ {+ "type": "BoxCollider3D",+ "data": {+ "halfExtents": {+ "x": 25,+ "y": 60,+ "z": 25+ },+ "isSensor": true+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "color": {+ "r": 0.35,+ "g": 0.42,+ "b": 0.72,+ "a": 1+ }+ }+ },+ {+ "type": "Health",+ "data": {+ "current": 100,+ "max": 100+ }+ }+ ]+ },+ {+ "id": 18,+ "name": "HitSparkB",+ "parent": 17,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "ParticleEmitter",+ "data": {+ "rate": 0,+ "burstCount": 18,+ "burstInterval": 0,+ "duration": 0.05,+ "looping": false,+ "playOnStart": false,+ "maxParticles": 72,+ "lifetimeMin": 0.5,+ "lifetimeMax": 0.9,+ "shape": 4,+ "shapeRadius": 12,+ "speedMin": 90,+ "speedMax": 240,+ "startSizeMin": 8,+ "startSizeMax": 14,+ "endSizeMin": 0,+ "endSizeMax": 4,+ "startColor": {+ "r": 1.0,+ "g": 0.82,+ "b": 0.45,+ "a": 1.0+ },+ "endColor": {+ "r": 0.95,+ "g": 0.32,+ "b": 0.2,+ "a": 0.0+ },+ "gravity": {+ "x": 0,+ "y": -320,+ "z": 0+ },+ "damping": 2.0,+ "blendMode": 1,+ "layer": 0,+ "simulationSpace": 0+ }+ }+ ]}]}\ No newline at end of filediff --git a/examples/third-person-3d/assets/scenes/main.esscene b/examples/third-person-3d/assets/scenes/main.essceneindex 69d185255..1ceaeb0fe 100644--- a/examples/third-person-3d/assets/scenes/main.esscene+++ b/examples/third-person-3d/assets/scenes/main.esscene@@ -343,6 +343,21 @@"data": {"enabled": true}+ },+ {+ "type": "MeleeAttack",+ "data": {+ "radius": 70,+ "damage": 25,+ "anchor": 15+ }+ },+ {+ "type": "Health",+ "data": {+ "current": 100,+ "max": 100+ }}]},@@ -369,7 +384,9 @@"id": 7,"name": "Bone1","parent": 5,- "children": [],+ "children": [+ 15+ ],"visible": true,"components": [{@@ -733,6 +750,269 @@}}]+ },+ {+ "id": 15,+ "name": "HitAnchor",+ "parent": 7,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 80,+ "y": 0,+ "z": 0+ }+ }+ }+ ]+ },+ {+ "id": 16,+ "name": "DummyA",+ "parent": null,+ "children": [+ 17+ ],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 129,+ "y": 60,+ "z": 17+ }+ }+ },+ {+ "type": "RigidBody3D",+ "data": {+ "bodyType": 0+ }+ },+ {+ "type": "BoxCollider3D",+ "data": {+ "halfExtents": {+ "x": 25,+ "y": 60,+ "z": 25+ },+ "isSensor": true+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "color": {+ "r": 0.78,+ "g": 0.35,+ "b": 0.32,+ "a": 1+ }+ }+ },+ {+ "type": "Health",+ "data": {+ "current": 100,+ "max": 100+ }+ }+ ]+ },+ {+ "id": 17,+ "name": "HitSparkA",+ "parent": 16,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "ParticleEmitter",+ "data": {+ "rate": 0,+ "burstCount": 18,+ "burstInterval": 0,+ "duration": 0.05,+ "looping": false,+ "playOnStart": false,+ "maxParticles": 72,+ "lifetimeMin": 0.5,+ "lifetimeMax": 0.9,+ "shape": 4,+ "shapeRadius": 12,+ "speedMin": 90,+ "speedMax": 240,+ "startSizeMin": 8,+ "startSizeMax": 14,+ "endSizeMin": 0,+ "endSizeMax": 4,+ "startColor": {+ "r": 1.0,+ "g": 0.82,+ "b": 0.45,+ "a": 1.0+ },+ "endColor": {+ "r": 0.95,+ "g": 0.32,+ "b": 0.2,+ "a": 0.0+ },+ "gravity": {+ "x": 0,+ "y": -320,+ "z": 0+ },+ "damping": 2.0,+ "blendMode": 1,+ "layer": 0,+ "simulationSpace": 0+ }+ }+ ]+ },+ {+ "id": 18,+ "name": "DummyB",+ "parent": null,+ "children": [+ 19+ ],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": -129,+ "y": 60,+ "z": 17+ }+ }+ },+ {+ "type": "RigidBody3D",+ "data": {+ "bodyType": 0+ }+ },+ {+ "type": "BoxCollider3D",+ "data": {+ "halfExtents": {+ "x": 25,+ "y": 60,+ "z": 25+ },+ "isSensor": true+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "color": {+ "r": 0.35,+ "g": 0.42,+ "b": 0.72,+ "a": 1+ }+ }+ },+ {+ "type": "Health",+ "data": {+ "current": 100,+ "max": 100+ }+ }+ ]+ },+ {+ "id": 19,+ "name": "HitSparkB",+ "parent": 18,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "ParticleEmitter",+ "data": {+ "rate": 0,+ "burstCount": 18,+ "burstInterval": 0,+ "duration": 0.05,+ "looping": false,+ "playOnStart": false,+ "maxParticles": 72,+ "lifetimeMin": 0.5,+ "lifetimeMax": 0.9,+ "shape": 4,+ "shapeRadius": 12,+ "speedMin": 90,+ "speedMax": 240,+ "startSizeMin": 8,+ "startSizeMax": 14,+ "endSizeMin": 0,+ "endSizeMax": 4,+ "startColor": {+ "r": 1.0,+ "g": 0.82,+ "b": 0.45,+ "a": 1.0+ },+ "endColor": {+ "r": 0.95,+ "g": 0.32,+ "b": 0.2,+ "a": 0.0+ },+ "gravity": {+ "x": 0,+ "y": -320,+ "z": 0+ },+ "damping": 2.0,+ "blendMode": 1,+ "layer": 0,+ "simulationSpace": 0+ }+ }+ ]}]}diff --git a/examples/third-person-3d/src/main.ts b/examples/third-person-3d/src/main.tsindex d31b6377c..c38be4b88 100644--- a/examples/third-person-3d/src/main.ts+++ b/examples/third-person-3d/src/main.ts@@ -1,15 +1,16 @@// Movement is declared, not scripted: ThirdPersonController and// ThirdPersonCamera are components the scene carries. What a game DOES own is-// what an animation means — here, that a footstep throws up dust.+// what an animation and a blow MEAN — here, dust under a footstep and sparks+// where a sword lands.import {addSystemToSchedule, Schedule, defineSystem, EventReader, GetWorld, Res,- AnimatorEvent, Particle, resolveChildEntity,+ AnimatorEvent, Damage, Children, ParticleEmitter, Particle, resolveChildEntity,} from 'esengine';/**- * Dust on a footstep. The animator says WHEN a foot lands — it is a moment the- * walk clip declares, not a guess from speed — and the effect under that- * character is what answers. Nothing here reads a clip or a clock.+ * Dust on a footstep. The animator says WHEN a foot lands — a moment the walk+ * clip declares, not a guess from speed — and the effect under that character+ * answers. Nothing here reads a clip or a clock.*/const footstepDustSystem = defineSystem([EventReader(AnimatorEvent), GetWorld(), Res(Particle)],@@ -23,4 +24,23 @@ const footstepDustSystem = defineSystem({ name: 'FootstepDustSystem' },);+/**+ * Sparks where a blow landed. Driven by the blow itself, so nothing burns while+ * nothing is being hit — and by the effect the TARGET carries, so the engine+ * never has to know which sword makes which sparks.+ */+const hitSparkSystem = defineSystem(+ [EventReader(Damage), GetWorld(), Res(Particle)],+ (blows, world, particles) => {+ for (const blow of blows) {+ if (!world.has(blow.target, Children)) continue;+ for (const child of world.get(blow.target, Children).entities) {+ if (world.has(child, ParticleEmitter)) particles.play(child);+ }+ }+ },+ { name: 'HitSparkSystem' },+);+addSystemToSchedule(Schedule.Update, footstepDustSystem);+addSystemToSchedule(Schedule.Update, hitSparkSystem);diff --git a/pipeline/src/runtime/gameHost.ts b/pipeline/src/runtime/gameHost.tsindex e28195657..c8ab1cb6a 100644--- a/pipeline/src/runtime/gameHost.ts+++ b/pipeline/src/runtime/gameHost.ts@@ -17,7 +17,7 @@ import {HttpBackend, fetchDecodePixels, registerPackagedSideModules,packagedAppOptions, packagedRuntimeInit, Transform, SceneManager, Nav, UINode,acquireWebGPUDevice, ThirdPersonCamera, CharacterController3D, AnimatorController,- Animator, TPC_SPEED, TPC_GROUNDED, Particle,+ Animator, TPC_SPEED, TPC_GROUNDED, Particle, MeleeAttack, Health,} from 'esengine';import type { SceneData, AddressableManifest, PackagedGameConfig, RenderSurfaceSource } from 'esengine';import type { ESEngineModule } from 'esengine/wasm';@@ -191,6 +191,38 @@ async function boot(): Promise<void> {// "the thing I was walking to is gone", which is a lie with a cost.return { scene: scenes?.getActive() ?? null, transitioning: scenes?.isTransitioning() ?? false, at };},+ /**+ * What a swing IS and what it has done to whom: the live attack instance+ * and every named target's health. Off the same components the game runs+ * on, and read-only — a driver that could deal damage would be answering+ * its own question, so damage still has to come from the keyboard.+ */+ combat(attackerName: string, targetNames: string[] = []): {+ attack: { id: number; hitCount: number; state: string } | null;+ targets: Record<string, { health: number; max: number }>;+ } {+ const targets: Record<string, { health: number; max: number }> = {};+ for (const name of targetNames) {+ const entity = app.world.findEntityByName(name);+ if (entity === null || !app.world.has(entity, Health)) continue;+ const health = app.world.get(entity, Health);+ targets[name] = { health: health.current, max: health.max };+ }+ const attacker = app.world.findEntityByName(attackerName);+ if (attacker === null || !app.world.has(attacker, MeleeAttack)) {+ return { attack: null, targets };+ }+ const melee = app.world.get(attacker, MeleeAttack);+ return {+ attack: {+ id: melee.attackId,+ hitCount: melee.hitCount,+ state: app.world.has(attacker, Animator)+ ? app.world.get(attacker, Animator).currentState : '',+ },+ targets,+ };+ },/*** How many particles a named emitter is running. The far END of a chain* that starts in a clip: nothing else can say a moment the animationdiff --git a/tools/launchers/launch-export.mjs b/tools/launchers/launch-export.mjsindex 85761206a..b4993b8b6 100644--- a/tools/launchers/launch-export.mjs+++ b/tools/launchers/launch-export.mjs@@ -31,6 +31,8 @@* (opens the package with ?headless)* --particles a[,b] after settling, print how many particles named emitters* are running — the far end of an effect chain+ * --combat p:a[,b] after settling, print the live swing and what each+ * named target has left* --gameplay p[,c] after settling, print what the third-person character* IS: where it stands, what the physics step gave it, and* what its animator was told@@ -149,11 +151,12 @@ async function main() {const PROBE = flag('probe', '');const GAMEPLAY = flag('gameplay', '');const PARTICLES = flag('particles', '');+const COMBAT = flag('combat', '');/** Boot a named scene from the package instead of its entry. */const SCENE = flag('scene', '');const server = await serve(DIR, flag('safe-area', ''));const query = new URLSearchParams();- if (PROBE || GAMEPLAY || PARTICLES) query.set('headless', '');+ if (PROBE || GAMEPLAY || PARTICLES || COMBAT) query.set('headless', '');if (SCENE) query.set('scene', SCENE);const search = query.toString() ? `?${query.toString().replace(/=$/, '').replace(/=&/g, '&')}` : '';const base = `http://127.0.0.1:${server.address().port}/${search}`;@@ -232,6 +235,16 @@ const SCENE = flag('scene', '');console.log(` particles: ${JSON.stringify(seen)}`);}+ if (COMBAT) {+ const [attacker, targets = ''] = COMBAT.split(':');+ const names = targets.split(',').map((n) => n.trim()).filter(Boolean);+ const seen = await win.webContents.executeJavaScript(+ `window.__estellaCooked?.combat(${JSON.stringify(attacker.trim())}, `+ + `${JSON.stringify(names)}) ?? null`,+ ).catch((e) => ({ error: String(e) }));+ console.log(` combat: ${JSON.stringify(seen)}`);+ }+const image = await win.webContents.capturePage();if (OUT) await writeFile(OUT, image.toPNG());stop();diff --git a/tools/verify-third-person.mjs b/tools/verify-third-person.mjsindex c13e0c336..24701d50f 100644--- a/tools/verify-third-person.mjs+++ b/tools/verify-third-person.mjs@@ -69,7 +69,8 @@ function run(dir, input) {LAUNCHER, '--dir', dir, '--w', String(W), '--h', String(H),'--settle', '30', '--timeout', '60000', '--scene', 'gym','--input', JSON.stringify(input), '--gameplay', 'Player,Camera',- '--particles', 'FootDust',+ '--particles', 'FootDust,HitSparkA,HitSparkB',+ '--combat', 'Player:DummyA,DummyB,Player','--out', path.join(WORK, 'frame.png'),], { encoding: 'utf8', cwd: ROOT });const seen = reading(r.stdout, 'gameplay');@@ -79,9 +80,16 @@ function run(dir, input) {// The far end of the effect chain, beside what the character became: the// reading is one launch, so asking twice would be two different games.seen.particles = reading(r.stdout, 'particles') ?? {};+ seen.combat = reading(r.stdout, 'combat') ?? { attack: null, targets: {} };return seen;}+/** Press the attack key at `at`, for the three frames a press needs to be seen. */+const ATTACK = (at) => ({ key: 'KeyJ', from: at, to: at + 3 });+/** What each named target has left, and what the swing has done. */+const health = (r, name) => r.combat?.targets?.[name]?.health;+const swing = (r) => r.combat?.attack ?? {};+/*** Walk a lane: strafe to it over `strafe` frames, then hold forward to the end.* Forward is never RELEASED - a wall claim is about the stick still being full,@@ -304,6 +312,82 @@ const START = { y: 60, z: 120 };+ ` real ${wallReal.toFixed(0)}, z ${held.position?.z?.toFixed(0)}`);}+// 11. A swing: the animation decides WHEN, physics decides WHO, gameplay decides+// what that does. Every reading is taken while the swing is still live, so the+// attack instance itself is visible rather than inferred from the aftermath.+{+ // The clip's `hit` beats sit at 0.45s and 0.60s of a 1s attack; a press at+ // frame 5 puts them around frames 32 and 41 at the rate this harness runs.+ const attacking = (extra = [], frames = 50) =>+ run(dir, { holds: [ATTACK(5), ...extra], frames });++ // C — before the animation says it connects, nothing has happened yet.+ const early = attacking([], 17);+ check('a swing that has not connected yet has taken nothing off',+ swing(early).state === 'Attack1' && swing(early).hitCount === 0+ && health(early, 'DummyA') === 100,+ `state ${swing(early).state}, hits ${swing(early).hitCount},`+ + ` A ${health(early, 'DummyA')}`);++ // B + E — past the beat: the one beside the swing loses health, the one on+ // the other side of the character does not.+ const landed = attacking();+ check('and past it, the target the swing reached loses exactly one blow',+ swing(landed).hitCount === 1 && health(landed, 'DummyA') === 75,+ `hits ${swing(landed).hitCount}, A ${health(landed, 'DummyA')}`);+ // The mirror of A through the character's forward axis, and a hit volume+ // rather than an obstacle — a target that stood in the lanes would answer+ // the locomotion criteria instead of this one.+ check('while its mirror on the other side stays untouched',+ health(landed, 'DummyB') === 100 && health(landed, 'Player') === 100,+ `B ${health(landed, 'DummyB')}, self ${health(landed, 'Player')}`);+ check('and the sparks are the blow’s, not an effect left running',+ (early.particles?.HitSparkA ?? -1) === 0+ && (landed.particles?.HitSparkA ?? 0) > 0+ && (landed.particles?.HitSparkB ?? -1) === 0,+ `A ${early.particles?.HitSparkA}→${landed.particles?.HitSparkA},`+ + ` B ${landed.particles?.HitSparkB}`);++ // D — the clip says `hit` twice, and the swing still lands once.+ const twice = run(dir, { holds: [ATTACK(5), ATTACK(80)], frames: 125 });+ check('a second swing may land on what the first one already hit',+ swing(twice).hitCount === 1 && health(twice, 'DummyA') === 50,+ `hits ${swing(twice).hitCount}, A ${health(twice, 'DummyA')}`);++ // A — the same swing where there is nothing to reach.+ const missed = run(dir, {+ holds: [{ key: 'KeyS', from: 0, to: 45 }, ATTACK(50)],+ frames: 95,+ });+ check('a swing with nothing in reach runs and takes nothing off',+ swing(missed).state === 'Attack1' && (swing(missed).id ?? 0) > 0+ && swing(missed).hitCount === 0 && health(missed, 'DummyA') === 100+ && (missed.particles?.HitSparkA ?? -1) === 0,+ `attack ${swing(missed).id}, hits ${swing(missed).hitCount},`+ + ` A ${health(missed, 'DummyA')}, sparks ${missed.particles?.HitSparkA}`);+}++// 12. The attack lunges, which makes it the same question the dodge answered:+// what the animation asks for is not what the world allows.+{+ const lunged = run(dir, { holds: [ATTACK(5)], frames: 70 });+ const travelled = START.z - (lunged.position?.z ?? START.z);+ check('an attack carries the character forward',+ travelled > 40, `travelled ${travelled.toFixed(0)}`);++ const atWall = run(dir, {+ holds: [+ { key: 'KeyD', from: 0, to: TO_LANE.wall },+ { key: 'KeyW', from: TO_LANE.wall, to: TO_LANE.wall + 151 },+ ATTACK(TO_LANE.wall + 135),+ ],+ frames: TO_LANE.wall + 180,+ });+ check('and the same attack against a wall plays without going through it',+ swing(atWall).state === 'Attack1' && (atWall.position?.z ?? -999) > -520,+ `state ${swing(atWall).state}, z ${atWall.position?.z?.toFixed(0)}`);+}+const failed = results.filter((r) => !r.ok);console.log(`\nverify-third-person: ${results.length - failed.length}/${results.length}`+ ' behaviour(s) hold up in the packaged game.');