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
Enemy AI
Two enemies hunt the player, each driven by a different, editor-authored AI asset, but sharing the same senses and actions:
- Enemy A runs a state machine (
assets/ai/enemy.esfsm):Patrol ⇄ Chase. - Enemy B runs a behavior tree (
assets/ai/enemy.esbt): a Selector that chases when it sees the player, otherwise patrols.
Move the player with WASD / arrow keys; walk into an enemy's sight range and it paths toward you (A* navigation), then breaks off and idles when you slip away.
What it shows
- Editor-authored AI assets, not code. Open
assets/ai/enemy.esfsmandassets/ai/enemy.esbtin the editor (double-click them in the Content Browser) to see and edit the graphs. The scene'sStateMachineAgent.fsm/BehaviorTreeAgent.btjust point at these asset paths; the engine loads them — there is noregisterFsm/registerBtin the project code. - A state machine and a behavior tree side by side — the same behavior, two paradigms, so you can compare them.
- One shared registry. The
seesPlayer/lostPlayerconditions and thechase/patrolactions (insrc/enemy.ts) serve both the FSM and the BT. - Perception → decision → navigation. A
Perceiversenses the player (aPerceptionTarget) into aPerceptioncomponent; the FSM/BT read it viactx.get(Perception); thechaseaction callssetNavDestination, and the built-in nav plugin paths the agent there.
Files
assets/ai/enemy.esfsm— the state machine (open it in the editor to edit).assets/ai/enemy.esbt— the behavior tree (open it in the editor to edit).src/enemy.ts— the shared conditions/actions + the startup nav grid.src/player.ts+src/components.ts— the WASD player and itsPlayerControl.src/main.ts— registers the player + nav-grid systems (perception, the FSM/BT ticks and nav follow are all built-in engine plugins).
StateMachineAgent / BehaviorTreeAgent / NavAgent / Perceiver /
PerceptionTarget are engine built-ins, so they aren't declared in
src/components.ts — only the project's own PlayerControl is.