Efe Anidi
Simulation & agents

Yuka

A standalone JavaScript game AI library: steering, state machines, goal-driven agents, navigation meshes and fuzzy logic.

Best for
Classic game AI for web games
Pricing
Free (open source)
Licence
MIT
Site
mugen87.github.io ↗

What it is

Yuka is a JavaScript library for game AI, written by Michael Herzog (Mugen87, also a long-time three.js maintainer) and hosted at github.com/Mugen87/yuka. It packages the well-known techniques from Mat Buckland’s Programming Game AI by Example into a modern ES module: a game entity model, vehicles with steering behaviours, finite state machines, goal-driven agents, graph search, navigation meshes, perception with vision and short-term memory, triggers, a fuzzy inference system, and JSON serialisation of the game state.

It does no rendering. Yuka is independent of any 3D engine, and the official examples pair it with three.js by copying each entity’s transform onto a mesh every frame.

On status: the latest npm release is 0.7.8 from September 2022, and the last commits to the main branch are from early 2023. The repository is not archived and the documentation and examples are still online, but it is best treated as finished rather than actively developed.

Where it fits in AI-driven worlds

A lot of what makes a game world feel inhabited is not machine learning at all. It is agents that steer around each other, patrol, flee, pursue, notice the player, remember where they last saw them and switch between behaviours sensibly. Yuka covers exactly that layer for browser games.

It is useful as the deterministic, cheap layer underneath anything more ambitious. A language model or planner can decide what an NPC wants; Yuka’s goals, state machines and steering can turn that decision into movement that looks right at 60 frames per second. Keeping the two separate also means the game still works when the expensive layer is slow or unavailable.

It is also a clear reference implementation. The code is readable and maps closely to the textbook, so even if you end up writing your own system, reading Yuka’s SteeringManager or Think and Goal classes is a good way to learn the patterns.

Strengths

  • Broad coverage. Steering, FSMs, goal arbitration, A* and Dijkstra on graphs, navmeshes, vision, memory and fuzzy logic in one coherent package.
  • Engine-agnostic. Works with three.js, Babylon.js, PlayCanvas or a plain canvas. You sync transforms yourself.
  • Small and dependency-free. It is plain JavaScript with ES module imports.
  • Good examples. The examples site demonstrates most features with live demos and readable source.
  • Permissive licence. MIT.

Limits

  • Dormant. No releases since 2022. Bugs are unlikely to be fixed upstream, and it will not track new ideas or APIs.
  • No TypeScript types shipped. You get JSDoc in the source, but not first-class typings.
  • Object-oriented design. Each entity is a class instance. That is easy to read but does not scale to tens of thousands of agents the way a data-oriented ECS such as bitECS does.
  • Navmesh tooling is external. Yuka loads navigation meshes (for example from glTF), but you generate them with other tools.
  • Classic techniques only. There is nothing for learned behaviour; that is out of scope by design.

Getting started

npm install yuka

A vehicle seeking a target, updated by an entity manager. Tested against yuka 0.7.8 in Node:

import * as YUKA from 'yuka';

const entityManager = new YUKA.EntityManager();
const time = new YUKA.Time();

const vehicle = new YUKA.Vehicle();
vehicle.maxSpeed = 2;
vehicle.steering.add(new YUKA.SeekBehavior(new YUKA.Vector3(10, 0, 5)));
entityManager.add(vehicle);

function tick() {
  const delta = time.update().getDelta();
  entityManager.update(delta);
  // copy vehicle.position and vehicle.rotation onto your rendered mesh here
  requestAnimationFrame(tick);
}
tick();

In a three.js scene, the examples set vehicle.setRenderComponent(mesh, sync) with a small callback that copies the entity’s world matrix to the mesh, which saves doing it by hand.

Verdict

Yuka is a tidy, well-designed implementation of classic game AI for the web, and still works well for steering, state machines and pathfinding in a browser game. The catch is that it has not had a release since 2022, so adopt it knowing you may need to maintain your own fork. Even then, it is worth having as a reference.

More in Simulation & agents