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): an autonomous character, claimed in the packaged game
esengine604133744773
diff --git a/examples/third-person-3d/assets/scenes/arena.esscene b/examples/third-person-3d/assets/scenes/arena.esscenenew file mode 100644index 000000000..237185c05--- /dev/null+++ b/examples/third-person-3d/assets/scenes/arena.esscene@@ -0,0 +1,824 @@+{+ "version": 4,+ "name": "arena",+ "entities": [+ {+ "id": 0,+ "name": "Camera",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 200,+ "z": 500+ }+ }+ },+ {+ "type": "Camera",+ "data": {+ "projectionType": 0,+ "fov": 55,+ "nearPlane": 10,+ "farPlane": 4000,+ "isActive": true,+ "priority": 0+ }+ },+ {+ "type": "ThirdPersonCamera",+ "data": {+ "target": 7,+ "distance": 420,+ "pitch": 18+ }+ },+ {+ "type": "PostProcessVolume",+ "data": {+ "isGlobal": true,+ "priority": 0,+ "weight": 1,+ "effects": [+ {+ "type": "ssao",+ "enabled": true,+ "uniforms": {+ "u_radius": 70,+ "u_intensity": 1,+ "u_bias": 0.12,+ "u_power": 1.6+ }+ }+ ]+ }+ }+ ]+ },+ {+ "id": 1,+ "name": "Ground",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": -20,+ "z": -100+ },+ "scale": {+ "x": 24,+ "y": 0.4,+ "z": 20+ }+ }+ },+ {+ "type": "RigidBody3D",+ "data": {+ "bodyType": 0+ }+ },+ {+ "type": "BoxCollider3D",+ "data": {+ "halfExtents": {+ "x": 1200,+ "y": 20,+ "z": 1000+ },+ "friction": 0.6+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "color": {+ "r": 0.3,+ "g": 0.34,+ "b": 0.3,+ "a": 1+ }+ }+ }+ ]+ },+ {+ "id": 2,+ "name": "Barrier",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 45,+ "z": -100+ },+ "scale": {+ "x": 4,+ "y": 0.9,+ "z": 0.6+ }+ }+ },+ {+ "type": "RigidBody3D",+ "data": {+ "bodyType": 0,+ "layer": 2+ }+ },+ {+ "type": "BoxCollider3D",+ "data": {+ "halfExtents": {+ "x": 200,+ "y": 45,+ "z": 30+ },+ "friction": 0.6+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "color": {+ "r": 0.5,+ "g": 0.36,+ "b": 0.3,+ "a": 1+ }+ }+ }+ ]+ },+ {+ "id": 3,+ "name": "Perch",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 400,+ "y": 45,+ "z": 150+ },+ "scale": {+ "x": 2.4,+ "y": 0.9,+ "z": 2.4+ }+ }+ },+ {+ "type": "RigidBody3D",+ "data": {+ "bodyType": 0+ }+ },+ {+ "type": "BoxCollider3D",+ "data": {+ "halfExtents": {+ "x": 120,+ "y": 45,+ "z": 120+ },+ "friction": 0.6+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "builtin:cube",+ "lit": true,+ "opaque": true,+ "cullBackfaces": true,+ "color": {+ "r": 0.42,+ "g": 0.44,+ "b": 0.52,+ "a": 1+ }+ }+ }+ ]+ },+ {+ "id": 4,+ "name": "NavVolume",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 125,+ "z": 0+ }+ }+ },+ {+ "type": "NavVolume",+ "data": {+ "halfExtents": {+ "x": 800,+ "y": 200,+ "z": 600+ },+ "cellSize": 25,+ "cellHeight": 10,+ "agentHeight": 120,+ "agentRadius": 30,+ "stepHeight": 40+ }+ }+ ]+ },+ {+ "id": 5,+ "name": "Sun",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ },+ "rotation": {+ "w": 0.83394695,+ "x": -0.52086316,+ "y": 0.18230211,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 1,+ "intensity": 1.05,+ "enabled": true,+ "color": {+ "r": 1,+ "g": 0.96,+ "b": 0.9,+ "a": 1+ }+ }+ }+ ]+ },+ {+ "id": 6,+ "name": "Sky",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "Light",+ "data": {+ "type": 2,+ "intensity": 0.42,+ "enabled": true,+ "color": {+ "r": 0.55,+ "g": 0.66,+ "b": 0.85,+ "a": 1+ }+ }+ }+ ]+ },+ {+ "id": 7,+ "name": "Player",+ "parent": null,+ "children": [+ 8,+ 9,+ 10,+ 11+ ],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 60,+ "z": 150+ }+ }+ },+ {+ "type": "CharacterController3D",+ "data": {+ "radius": 30,+ "halfHeight": 30,+ "stepHeight": 40,+ "snapDown": 50+ }+ },+ {+ "type": "ThirdPersonController",+ "data": {+ "camera": 0,+ "moveSpeed": 320,+ "jumpSpeed": 520,+ "idleThreshold": 8+ }+ },+ {+ "type": "Animator",+ "data": {+ "controller": "assets/models/locomotion.esanimator",+ "currentState": "",+ "enabled": true+ }+ },+ {+ "type": "AnimatorRootMotion",+ "data": {+ "enabled": true+ }+ },+ {+ "type": "MeleeAttack",+ "data": {+ "radius": 110,+ "damage": 25,+ "anchor": 12+ }+ },+ {+ "type": "Health",+ "data": {+ "current": 100,+ "max": 100+ }+ },+ {+ "type": "PerceptionTarget",+ "data": {}+ }+ ]+ },+ {+ "id": 8,+ "name": "Bone0",+ "parent": 7,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ }+ ]+ },+ {+ "id": 9,+ "name": "Bone1",+ "parent": 7,+ "children": [+ 12+ ],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 60,+ "y": 0,+ "z": 0+ }+ }+ }+ ]+ },+ {+ "id": 10,+ "name": "Body",+ "parent": 7,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "assets/models/skinned-fade.esmesh",+ "lit": true,+ "opaque": true,+ "color": {+ "r": 0.35,+ "g": 0.75,+ "b": 0.45,+ "a": 1+ }+ }+ },+ {+ "type": "MeshSkin",+ "data": {+ "joints": [+ 8,+ 9+ ]+ }+ }+ ]+ },+ {+ "id": 11,+ "name": "FootDust",+ "parent": 7,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": -78,+ "z": 0+ }+ }+ },+ {+ "type": "ParticleEmitter",+ "data": {+ "rate": 0,+ "burstCount": 12,+ "burstInterval": 0,+ "duration": 0.05,+ "looping": false,+ "playOnStart": false,+ "maxParticles": 64,+ "lifetimeMin": 0.6,+ "lifetimeMax": 1,+ "shape": 5,+ "shapeRadius": 18,+ "speedMin": 18,+ "speedMax": 42,+ "startSizeMin": 10,+ "startSizeMax": 16,+ "endSizeMin": 22,+ "endSizeMax": 30,+ "sizeEasing": 2,+ "startColor": {+ "r": 0.74,+ "g": 0.68,+ "b": 0.56,+ "a": 0.35+ },+ "endColor": {+ "r": 0.66,+ "g": 0.62,+ "b": 0.54,+ "a": 0+ },+ "gravity": {+ "x": 0,+ "y": 26,+ "z": 0+ },+ "damping": 1.6,+ "blendMode": 0,+ "layer": 0,+ "simulationSpace": 0+ }+ }+ ]+ },+ {+ "id": 12,+ "name": "HitAnchor",+ "parent": 9,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 80,+ "y": 0,+ "z": 0+ }+ }+ }+ ]+ },+ {+ "id": 13,+ "name": "Enemy",+ "parent": null,+ "children": [+ 14,+ 15,+ 16+ ],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 60,+ "z": -350+ }+ }+ },+ {+ "type": "CharacterController3D",+ "data": {+ "radius": 30,+ "halfHeight": 30,+ "stepHeight": 40,+ "snapDown": 50+ }+ },+ {+ "type": "NavAgent",+ "data": {+ "speed": 320,+ "radius": 30,+ "arriveRadius": 40,+ "repathInterval": 0.35+ }+ },+ {+ "type": "Perceiver",+ "data": {+ "range": 420,+ "fovDegrees": 360,+ "losLayers": 1+ }+ },+ {+ "type": "Perception",+ "data": {}+ },+ {+ "type": "Hunter",+ "data": {+ "attackRange": 100,+ "attackInterval": 1.6+ }+ },+ {+ "type": "Animator",+ "data": {+ "controller": "assets/models/locomotion.esanimator",+ "currentState": "",+ "enabled": true+ }+ },+ {+ "type": "MeleeAttack",+ "data": {+ "radius": 110,+ "damage": 20,+ "anchor": 18+ }+ },+ {+ "type": "Health",+ "data": {+ "current": 25,+ "max": 25+ }+ }+ ]+ },+ {+ "id": 14,+ "name": "Bone0",+ "parent": 13,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ }+ ]+ },+ {+ "id": 15,+ "name": "Bone1",+ "parent": 13,+ "children": [+ 18+ ],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 60,+ "y": 0,+ "z": 0+ }+ }+ }+ ]+ },+ {+ "id": 16,+ "name": "EnemyBody",+ "parent": 13,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ },+ {+ "type": "MeshRenderer",+ "data": {+ "mesh": "assets/models/skinned-fade.esmesh",+ "lit": true,+ "opaque": true,+ "color": {+ "r": 0.82,+ "g": 0.32,+ "b": 0.3,+ "a": 1+ }+ }+ },+ {+ "type": "MeshSkin",+ "data": {+ "joints": [+ 14,+ 15+ ]+ }+ }+ ]+ },+ {+ "id": 18,+ "name": "EnemyHitAnchor",+ "parent": 15,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 80,+ "y": 0,+ "z": 0+ }+ }+ }+ ]+ },+ {+ "id": 19,+ "name": "HitSpark",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": -4000,+ "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/assets/scenes/arena.esscene.meta b/examples/third-person-3d/assets/scenes/arena.esscene.metanew file mode 100644index 000000000..c38043331--- /dev/null+++ b/examples/third-person-3d/assets/scenes/arena.esscene.meta@@ -0,0 +1,6 @@+{+ "uuid": "0b4f3dca-92cb-445e-a153-cc5752f6325b",+ "version": "2.0",+ "type": "scene",+ "importer": {}+}diff --git a/examples/third-person-3d/assets/scenes/gym.esscene b/examples/third-person-3d/assets/scenes/gym.essceneindex e9817e188..4242cfde6 100644--- a/examples/third-person-3d/assets/scenes/gym.esscene+++ b/examples/third-person-3d/assets/scenes/gym.esscene@@ -713,9 +713,7 @@"id": 15,"name": "DummyA","parent": null,- "children": [- 16- ],+ "children": [],"visible": true,"components": [{@@ -769,75 +767,11 @@}]},- {- "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- ],+ "children": [],"visible": true,"components": [{@@ -893,8 +827,8 @@},{"id": 18,- "name": "HitSparkB",- "parent": 17,+ "name": "HitSpark",+ "parent": null,"children": [],"visible": true,"components": [@@ -903,7 +837,7 @@"data": {"position": {"x": 0,- "y": 0,+ "y": -4000,"z": 0}}@@ -954,4 +888,4 @@]}]-}\ No newline at end of file+}diff --git a/examples/third-person-3d/assets/scenes/main.esscene b/examples/third-person-3d/assets/scenes/main.essceneindex 1ceaeb0fe..44a7d97ba 100644--- a/examples/third-person-3d/assets/scenes/main.esscene+++ b/examples/third-person-3d/assets/scenes/main.esscene@@ -358,6 +358,10 @@"current": 100,"max": 100}+ },+ {+ "type": "PerceptionTarget",+ "data": {}}]},@@ -771,19 +775,17 @@]},{- "id": 16,- "name": "DummyA",+ "id": 18,+ "name": "DummyB","parent": null,- "children": [- 17- ],+ "children": [],"visible": true,"components": [{"type": "Transform","data": {"position": {- "x": 129,+ "x": -129,"y": 60,"z": 17}@@ -814,9 +816,9 @@"opaque": true,"cullBackfaces": true,"color": {- "r": 0.78,- "g": 0.35,- "b": 0.32,+ "r": 0.35,+ "g": 0.42,+ "b": 0.72,"a": 1}}@@ -831,9 +833,9 @@]},{- "id": 17,- "name": "HitSparkA",- "parent": 16,+ "id": 19,+ "name": "HitSpark",+ "parent": null,"children": [],"visible": true,"components": [@@ -842,7 +844,7 @@"data": {"position": {"x": 0,- "y": 0,+ "y": -4000,"z": 0}}@@ -893,11 +895,13 @@]},{- "id": 18,- "name": "DummyB",+ "id": 20,+ "name": "Enemy","parent": null,"children": [- 19+ 21,+ 22,+ 23],"visible": true,"components": [@@ -905,57 +909,160 @@"type": "Transform","data": {"position": {- "x": -129,+ "x": 129,"y": 60,"z": 17}}},{- "type": "RigidBody3D",+ "type": "CharacterController3D","data": {- "bodyType": 0+ "radius": 30,+ "halfHeight": 30,+ "stepHeight": 40,+ "snapDown": 50}},{- "type": "BoxCollider3D",+ "type": "NavAgent","data": {- "halfExtents": {- "x": 25,- "y": 60,- "z": 25- },- "isSensor": true+ "speed": 320,+ "radius": 30,+ "arriveRadius": 40,+ "repathInterval": 0.35+ }+ },+ {+ "type": "Perceiver",+ "data": {+ "range": 420,+ "fovDegrees": 360,+ "losLayers": 1+ }+ },+ {+ "type": "Perception",+ "data": {}+ },+ {+ "type": "Hunter",+ "data": {+ "attackRange": 100,+ "attackInterval": 1.6+ }+ },+ {+ "type": "Animator",+ "data": {+ "controller": "assets/models/locomotion.esanimator",+ "currentState": "",+ "enabled": true+ }+ },+ {+ "type": "MeleeAttack",+ "data": {+ "radius": 110,+ "damage": 20,+ "anchor": 24+ }+ },+ {+ "type": "Health",+ "data": {+ "current": 50,+ "max": 50+ }+ }+ ]+ },+ {+ "id": 21,+ "name": "Bone0",+ "parent": 20,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }+ }+ }+ ]+ },+ {+ "id": 22,+ "name": "Bone1",+ "parent": 20,+ "children": [+ 24+ ],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 60,+ "y": 0,+ "z": 0+ }+ }+ }+ ]+ },+ {+ "id": 23,+ "name": "EnemyBody",+ "parent": 20,+ "children": [],+ "visible": true,+ "components": [+ {+ "type": "Transform",+ "data": {+ "position": {+ "x": 0,+ "y": 0,+ "z": 0+ }}},{"type": "MeshRenderer","data": {- "mesh": "builtin:cube",+ "mesh": "assets/models/skinned-fade.esmesh","lit": true,"opaque": true,- "cullBackfaces": true,"color": {- "r": 0.35,- "g": 0.42,- "b": 0.72,+ "r": 0.82,+ "g": 0.32,+ "b": 0.3,"a": 1}}},{- "type": "Health",+ "type": "MeshSkin","data": {- "current": 100,- "max": 100+ "joints": [+ 21,+ 22+ ]}}]},{- "id": 19,- "name": "HitSparkB",- "parent": 18,+ "id": 24,+ "name": "EnemyHitAnchor",+ "parent": 22,"children": [],"visible": true,"components": [@@ -963,53 +1070,44 @@"type": "Transform","data": {"position": {- "x": 0,+ "x": 80,"y": 0,"z": 0}}- },+ }+ ]+ },+ {+ "id": 25,+ "name": "NavVolume",+ "parent": null,+ "children": [],+ "visible": true,+ "components": [{- "type": "ParticleEmitter",+ "type": "Transform","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": {+ "position": {"x": 0,- "y": -320,- "z": 0+ "y": 125,+ "z": -300+ }+ }+ },+ {+ "type": "NavVolume",+ "data": {+ "halfExtents": {+ "x": 900,+ "y": 220,+ "z": 900},- "damping": 2.0,- "blendMode": 1,- "layer": 0,- "simulationSpace": 0+ "cellSize": 25,+ "cellHeight": 10,+ "agentHeight": 120,+ "agentRadius": 30,+ "stepHeight": 40}}]diff --git a/examples/third-person-3d/src/main.ts b/examples/third-person-3d/src/main.tsindex c38be4b88..caa75722a 100644--- a/examples/third-person-3d/src/main.ts+++ b/examples/third-person-3d/src/main.ts@@ -1,10 +1,9 @@-// Movement is declared, not scripted: ThirdPersonController and-// ThirdPersonCamera are components the scene carries. What a game DOES own is-// what an animation and a blow MEAN — here, dust under a footstep and sparks-// where a sword lands.+// Movement is declared, not scripted — ThirdPersonController, ThirdPersonCamera+// and Hunter are components the scene carries. What a game DOES own is what an+// animation and a blow MEAN: dust under a footstep, sparks where a sword lands.import {addSystemToSchedule, Schedule, defineSystem, EventReader, GetWorld, Res,- AnimatorEvent, Damage, Children, ParticleEmitter, Particle, resolveChildEntity,+ AnimatorEvent, Damage, Transform, Particle, resolveChildEntity,} from 'esengine';/**@@ -25,18 +24,21 @@ const footstepDustSystem = defineSystem();/**- * 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.+ * Sparks where a blow landed — moved to the contact point the blow carries,+ * which is the only moment it can be used: by the time this runs, the swing+ * that produced it has moved on. Driven by the blow, so nothing burns while+ * nothing is being hit, and by the same one for a player and for an enemy.*/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);- }+ const spark = world.findEntityByName('HitSpark');+ if (spark === null || !world.has(spark, Transform)) continue;+ world.update(spark, Transform, (t) => {+ t.position.x = blow.x; t.position.y = blow.y; t.position.z = blow.z;+ });+ particles.play(spark);}},{ name: 'HitSparkSystem' },diff --git a/pipeline/src/runtime/gameHost.ts b/pipeline/src/runtime/gameHost.tsindex c8ab1cb6a..2aed36c49 100644--- a/pipeline/src/runtime/gameHost.ts+++ b/pipeline/src/runtime/gameHost.ts@@ -18,6 +18,7 @@ import {packagedAppOptions, packagedRuntimeInit, Transform, SceneManager, Nav, UINode,acquireWebGPUDevice, ThirdPersonCamera, CharacterController3D, AnimatorController,Animator, TPC_SPEED, TPC_GROUNDED, Particle, MeleeAttack, Health,+ Hunter, NavAgent, Perception, AnimatorRootMotion,} from 'esengine';import type { SceneData, AddressableManifest, PackagedGameConfig, RenderSurfaceSource } from 'esengine';import type { ESEngineModule } from 'esengine/wasm';@@ -191,6 +192,73 @@ 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 an autonomous character is doing, and on whose terms. Read-only and+ * off the same components the game runs on: a driver that could set the+ * state would be answering its own question, so a chase still has to be+ * caused by walking into what the enemy can see.+ */+ ai(enemyName: string): {+ found: boolean;+ state: string;+ animator: string;+ visible: boolean;+ distance: number;+ hasTarget: boolean;+ target: { x: number; y: number; z: number } | null;+ askedVelocity: { x: number; z: number } | null;+ realVelocity: { x: number; z: number } | null;+ lunge: { x: number; z: number } | null;+ position: { x: number; y: number; z: number } | null;+ attackId: number;+ health: number;+ } {+ const blank = {+ found: false, state: '', animator: '', visible: false, distance: 0, hasTarget: false,+ target: null, askedVelocity: null, realVelocity: null, lunge: null, position: null,+ attackId: 0, health: 0,+ };+ const enemy = app.world.findEntityByName(enemyName);+ if (enemy === null || !app.world.has(enemy, Hunter)) return blank;+ // The composed placement is stale until something asks: a reading taken+ // between frames would otherwise report where the enemy was, beside a+ // distance computed from where it is.+ app.world.ensureTransformsComposed();++ const hunter = app.world.get(enemy, Hunter);+ const sight = app.world.has(enemy, Perception) ? app.world.get(enemy, Perception) : null;+ const agent = app.world.has(enemy, NavAgent) ? app.world.get(enemy, NavAgent) : null;+ const body = app.world.has(enemy, CharacterController3D)+ ? app.world.get(enemy, CharacterController3D) : null;+ const root = app.world.has(enemy, AnimatorRootMotion)+ ? app.world.get(enemy, AnimatorRootMotion) : null;+ const t = app.world.has(enemy, Transform) ? app.world.get(enemy, Transform) : null;+ const p = t ? (t.worldPosition ?? t.position) : null;+ return {+ found: true,+ state: hunter.state,+ animator: app.world.has(enemy, Animator)+ ? app.world.get(enemy, Animator).currentState : '',+ visible: sight?.visible ?? false,+ // The ground plane, which is what the hunter itself decides on — and+ // zero when nothing is seen, since the fields it would be read from+ // are stale rather than empty.+ distance: sight?.visible && p+ ? Math.hypot(sight.targetX - p.x, sight.targetZ - (p.z ?? 0)) : 0,+ hasTarget: agent?.hasTarget ?? false,+ target: agent ? { x: agent.targetX, y: agent.targetY, z: agent.targetZ } : null,+ askedVelocity: body ? { x: body.velocity.x, z: body.velocity.z } : null,+ realVelocity: body ? { x: body.realVelocity.x, z: body.realVelocity.z } : null,+ // What the ATTACK is asking for, as the rate it covers — the request the+ // steering velocity above has already been overwritten with or cleared.+ lunge: root?.active && root.deltaTime > 0+ ? { x: root.deltaPosition.x / root.deltaTime, z: root.deltaPosition.z / root.deltaTime }+ : null,+ position: p ? { x: p.x, y: p.y, z: p.z ?? 0 } : null,+ attackId: app.world.has(enemy, MeleeAttack) ? app.world.get(enemy, MeleeAttack).attackId : 0,+ health: app.world.has(enemy, Health) ? app.world.get(enemy, Health).current : 0,+ };+ },/*** 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 runsdiff --git a/tools/launchers/launch-export.mjs b/tools/launchers/launch-export.mjsindex b4993b8b6..4969eed24 100644--- a/tools/launchers/launch-export.mjs+++ b/tools/launchers/launch-export.mjs@@ -33,6 +33,8 @@* 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+ * --ai <enemy> after settling, print what an autonomous character is+ * doing, and what the world let it do* --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@@ -152,11 +154,12 @@ async function main() {const GAMEPLAY = flag('gameplay', '');const PARTICLES = flag('particles', '');const COMBAT = flag('combat', '');+const AI = flag('ai', '');/** 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 || COMBAT) query.set('headless', '');+ if (PROBE || GAMEPLAY || PARTICLES || COMBAT || AI) 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}`;@@ -245,6 +248,13 @@ const SCENE = flag('scene', '');console.log(` combat: ${JSON.stringify(seen)}`);}+ if (AI) {+ const seen = await win.webContents.executeJavaScript(+ `window.__estellaCooked?.ai(${JSON.stringify(AI.trim())}) ?? null`,+ ).catch((e) => ({ error: String(e) }));+ console.log(` ai: ${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 24701d50f..7b296e5d1 100644--- a/tools/verify-third-person.mjs+++ b/tools/verify-third-person.mjs@@ -63,14 +63,21 @@ function reading(stdout, label) {}}-/** Drive the package with one gesture and read what the character became. */-function run(dir, input) {+/**+ * Drive the package with one gesture and read what the character became.+ *+ * `scene` picks the fixture: `gym` answers to what a character DOES, `arena` to+ * what an autonomous one decides. Two, because a target one criterion needs+ * standing somewhere answers another's question — a solid one already did.+ */+function run(dir, input, scene = 'gym') {const r = runElectron([LAUNCHER, '--dir', dir, '--w', String(W), '--h', String(H),- '--settle', '30', '--timeout', '60000', '--scene', 'gym',+ '--settle', '30', '--timeout', '60000', '--scene', scene,'--input', JSON.stringify(input), '--gameplay', 'Player,Camera',- '--particles', 'FootDust,HitSparkA,HitSparkB',- '--combat', 'Player:DummyA,DummyB,Player',+ '--particles', 'FootDust,HitSpark',+ '--combat', 'Player:DummyA,DummyB,Player,Enemy',+ '--ai', 'Enemy','--out', path.join(WORK, 'frame.png'),], { encoding: 'utf8', cwd: ROOT });const seen = reading(r.stdout, 'gameplay');@@ -81,6 +88,7 @@ function run(dir, input) {// 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: {} };+ seen.ai = reading(r.stdout, 'ai') ?? { found: false };return seen;}@@ -342,11 +350,9 @@ const START = { y: 60, z: 120 };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}`);+ (early.particles?.HitSpark ?? -1) === 0+ && (landed.particles?.HitSpark ?? 0) > 0,+ `sparks ${early.particles?.HitSpark}→${landed.particles?.HitSpark}`);// D — the clip says `hit` twice, and the swing still lands once.const twice = run(dir, { holds: [ATTACK(5), ATTACK(80)], frames: 125 });@@ -362,9 +368,9 @@ const START = { y: 60, z: 120 };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,+ && (missed.particles?.HitSpark ?? -1) === 0,`attack ${swing(missed).id}, hits ${swing(missed).hitCount},`- + ` A ${health(missed, 'DummyA')}, sparks ${missed.particles?.HitSparkA}`);+ + ` A ${health(missed, 'DummyA')}, sparks ${missed.particles?.HitSpark}`);}// 12. The attack lunges, which makes it the same question the dodge answered:@@ -388,6 +394,84 @@ const START = { y: 60, z: 120 };`state ${swing(atWall).state}, z ${atWall.position?.z?.toFixed(0)}`);}+// 13. An autonomous character, in the arena fixture. Everything below is caused+// by the keyboard: the player walks into what the enemy can see, and every state+// the enemy reaches after that is its own.+{+ const arena = (input, frames) => run(dir, { ...input, frames }, 'arena');+ /** The player closes far enough to be seen; the enemy does the rest. */+ const seen = (frames, extra = []) =>+ arena({ holds: [{ key: 'KeyW', from: 0, to: 25 }, ...extra] }, frames);+ const ai = (r) => r.ai ?? {};+ const speed = (r) => Math.hypot(ai(r).realVelocity?.x ?? 0, ai(r).realVelocity?.z ?? 0);++ // 1. Detection. The pair is the claim: a chase that started on its own says+ // nothing about perception.+ const alone = arena({}, 40);+ check('an enemy that has seen nobody stands still',+ ai(alone).state === 'idle' && ai(alone).visible === false,+ `state ${ai(alone).state}, visible ${ai(alone).visible}`);++ const spotted = seen(40);+ check('and takes up the chase once the player walks into what it can see',+ ai(spotted).state === 'chase' && ai(spotted).visible === true+ && ai(spotted).hasTarget === true,+ `state ${ai(spotted).state}, visible ${ai(spotted).visible}`);++ // 2. The route. A wall it can see over stands between the two, so walking at+ // the player is not walking to the player.+ const rounding = seen(70);+ check('and goes around the barrier rather than into it',+ Math.abs(ai(rounding).position?.x ?? 0) > 150,+ `x ${ai(rounding).position?.x?.toFixed(0)} (straight would hold 0)`);++ // 3. Arrival, and the swing that follows — through the SAME pipeline: an+ // animator trigger, a beat the clip declares, MeleeAttack, Damage, Health.+ const swinging = seen(142);+ check('a swing of its own opens with the player still whole',+ ai(swinging).animator === 'Attack1' && ai(swinging).attackId > 0+ && health(swinging, 'Player') === 100,+ `anim ${ai(swinging).animator}, attack ${ai(swinging).attackId},`+ + ` player ${health(swinging, 'Player')}`);++ const struck = seen(175);+ check('and past the beat the player has lost exactly one blow',+ health(struck, 'Player') === 80 && (struck.particles?.HitSpark ?? 0) >= 0,+ `player ${health(struck, 'Player')}`);++ // 4. Out of reach again: a state that only left on its own would swing at air.+ const fleeing = seen(230, [{ key: 'KeyD', from: 170, to: 260 }]);+ check('a player who backs off is chased again rather than swung at',+ ai(fleeing).state === 'chase' && ai(fleeing).distance > 100,+ `state ${ai(fleeing).state}, distance ${ai(fleeing).distance?.toFixed(0)}`);++ // 5. Somewhere it cannot get to. The route ends where the mesh does, and the+ // enemy stops there — it does not pass through, and it does not give up.+ const stuck = arena({ holds: [{ key: 'KeyW', from: 0, to: 400 }] }, 340);+ const at = ai(stuck).position ?? { x: 0, z: 0 };+ const insideBarrier = Math.abs(at.x) < 230 && at.z > -160 && at.z < -40;+ check('a target it cannot reach leaves it stopped short, still trying',+ ai(stuck).state === 'chase' && speed(stuck) < 5 && !insideBarrier+ && health(stuck, 'Player') === 100,+ `state ${ai(stuck).state}, speed ${speed(stuck).toFixed(0)},`+ + ` at (${at.x.toFixed(0)}, ${at.z.toFixed(0)}), player ${health(stuck, 'Player')}`);++ // 6. And it can be killed, by the player's swing through the same pipeline.+ // One press: the player's own attack lunges, so a second would carry it back+ // out of reach before the first answer is in.+ const swings = [{ key: 'KeyA', from: 120, to: 150 }, ATTACK(170)];+ const dead = seen(260, swings);+ check('the player’s swing takes it down the same way its own works',+ ai(dead).state === 'dead' && health(dead, 'Enemy') === 0,+ `state ${ai(dead).state}, enemy ${health(dead, 'Enemy')}`);++ const after = seen(360, swings);+ check('and once it is down it stops moving and stops swinging',+ speed(after) < 5 && health(after, 'Player') === health(dead, 'Player'),+ `speed ${speed(after).toFixed(0)},`+ + ` player ${health(dead, 'Player')}→${health(after, 'Player')}`);+}+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.');