Steering
Updated
Steering gives characters lifelike AI movement that you build from small, reusable behaviours: seek a target, flee a threat, wander, follow a path, flock with others, queue at a door, follow a leader, avoid obstacles. Each behaviour is its own component and pushes the character in one direction with a certain weight. A Steering Agent on the same entity adds those pushes up every frame and moves the character. Because behaviours combine, a bird can flock, follow a leader and steer round crates all at once, and a script can switch behaviours on and off as the situation changes.
Before you start
Section titled “Before you start”- A steering agent can move a plain object directly. Give it a Character Controller with
controls: falsewhen it should walk with gravity and collisions; the controller then owns speed and turning. - To route round walls, add a NavMesh Agent too. See Navigation.
- Its event reaches scripts through a Signal Emitter on the agent’s entity.
How it fits together
Section titled “How it fits together”An agent entity carries:
- one Steering Agent, the brain that combines the behaviours;
- optionally one Character Controller with
controls: false, for an agent that walks with gravity and collisions; - any number of steering behaviours, each a force scaled by its
weight; - optionally a Steering Collidable, its size for the others to avoid.
Other entities carry a Steering Collidable to become obstacles that agents steer round.
The Steering Agent and the behaviours are offered on meshes and models, primitives and groups, so a group of meshes can steer as one agent.
How a frame works. Each enabled behaviour asks for a change of velocity. The agent sums them by weight, limits the result to maxForce, divides by mass, and caps the velocity at the effective speed. With no behaviour steering, the agent brakes to a stop. All steering happens on the ground plane: heights are ignored.
What moves the entity. With a Character Controller, the controller walks the agent at its own speed and turns it. Without one, an enabled NavMesh Agent walks the navmesh. Otherwise steering moves the entity directly on the ground plane, with no gravity or collisions. A Motion Path or a timeline that animates the transform takes priority and pauses steering.
Steering Agent
Section titled “Steering Agent”comp-steering-agent combines the entity’s behaviours.
| Prop | Type | Default | Description |
|---|---|---|---|
speed |
number | 4 |
Top speed, in metres per second, when there is no Character Controller. With one, the controller’s speed is used. |
maxForce |
number | 8 |
Largest steering acceleration, in m/s²: how sharply the velocity can change. |
mass |
number | 1 |
Inertia multiplier; the force is divided by it. Higher feels heavier. |
viewDistance |
number | 0 |
How far it sees its behaviours’ targets, in metres. 0 sees at any distance. |
viewAngle |
number | 360 |
How wide it sees, in degrees, centred on where it faces. 360 sees all round. |
| Member | What it does |
|---|---|
velocity |
Its velocity now, a THREE.Vector3 on the ground plane, in metres per second. Read it; the behaviours set it. |
speed |
The effective top speed. Assigning it changes the standalone setting. |
radius |
The size others keep away from: its own Steering Collidable’s radius, else 0.5. |
View. With a viewDistance, Seek, Arrive, Pursue, Flee, Evade and Follow Leader react only to a target inside a fan viewAngle wide and viewDistance long in front of the agent. A target that leaves the fan is still followed for two seconds, then forgotten until seen again. Wander, Interpose, Follow Path, Flock, Queue and Avoid ignore the view.
A script’s moveTo on the Character Controller pauses the behaviours until it arrives or stop() is called.
| Event | Constant | Data | When |
|---|---|---|---|
Steering |
Event |
{ position } |
A Steering Arrive reached its target, or a Steering Follow Path reached its last point. |
State changes and moveTo arrivals come from the Character Controller’s own events.
Steering behaviours
Section titled “Steering behaviours”Each behaviour is a Steering<Name>Component (comp-steering-<name>). An entity may carry several of each. Every behaviour has a weight, from 0 to 10, default 1: how much its push counts in the sum. 0 switches it off without disabling the component.
Six agents chase a beacon that jumps every five seconds: three with a Steering Seek rush at full speed, three with a Steering Arrive slow down within 3 m and report each stop.
Watch the blue seekers overshoot and brake hard while the green arrivers ease in; the label counts the Arrive stops. Drag to orbit the camera, scroll to zoom.
An amber cat with a Steering Pursue chases the nearest of four mice, cutting them off, while each mouse uses a Steering Evade to dodge where the cat is heading.
Watch the cat cut the mice off and the mice veer away once it comes within 3 m; the label names its current prey. Drag to orbit the camera, scroll to zoom.
An amber bodyguard with a Steering Interpose keeps itself between a wandering VIP and the threat that seeks it, and a label shows how close it is to the line between them.
Watch the amber bodyguard slide into place between the violet VIP and the blue threat, and follow them as they move. Drag to orbit the camera, scroll to zoom.
Five cars follow a looping Steering Follow Path round a track; the fast ones carry a Steering Queue, so they brake behind the slow amber car and wait in line.
Watch the blue cars catch up with the slow amber one and queue behind it; the speeds at the top drop as they brake. Drag to orbit the camera, scroll to zoom.
| Behaviour | Script class | Props (defaults) | What it does |
|---|---|---|---|
| Seek | Steering |
target, distance (0) |
Toward the target at full speed, braking to stop on it, or distance short of it. Backs off when the target comes nearer than distance. |
| Flee | Steering |
target, panicDistance (8) |
Away from the target while it is within panicDistance. |
| Arrive | Steering |
target, slowRadius (3), distance (0) |
Stops on the target, or distance short of it, and sends arrive once per stop. Starts slowing within slowRadius; 0 brakes automatically. |
| Pursue | Steering |
target, lead (0.5), distance (0) |
Toward where the target will be in lead seconds: it cuts the target off. |
| Evade | Steering |
target, lead (0.5), panicDistance (8) |
Away from where the target will be, while it is within panicDistance. |
| Wander | Steering |
range (6), jitter (3) |
Smooth random roaming. jitter is how fast its heading drifts, in radians per second. Past range from where it started, it turns home. |
| Interpose | Steering |
targetA, targetB |
Gets between two targets: a bodyguard. |
| Follow Path | Steering |
points ([]), repeat ('once'), radius (0.5) |
Visits the points in order; a point within radius counts as reached. Stops on the last and sends arrive, unless repeat is 'repeat'. restart() starts again from the first point. |
| Flock | Steering |
radius (3), separation (1.5), alignment (1), cohesion (1) |
Boids: keep apart from, match heading with and stay close to other agents within radius. |
| Queue | Steering |
radius (1.5) |
Brakes behind another agent in its lane, and goes on when the lane clears. |
| Follow Leader | Steering |
leader, distance (2), sightRadius (3) |
Keeps distance behind the leader, facing it, and steps aside when the leader walks at it. |
| Avoid | Steering |
lookAhead (3) |
Steers round the nearest Steering Collidable in its way, looking lookAhead metres ahead at full speed. |
- Targets.
target,targetA,targetBandleadertake an entity’s id or name. From a script you can also pass the entity itself. Empty, the behaviour does not steer. - Path points are a list of world-space
[x, y, z]arrays, up to 1024 of them. Setting new points restarts the route. - On a navmesh. With a NavMesh Agent on the entity, Seek, Arrive, Pursue and Follow Leader steer along a navmesh path to their goal, so they go round walls. Elsewhere steering is straight.
Steering Collidable
Section titled “Steering Collidable”comp-steering-collidable is something agents see and keep clear of: a crate, a post, a statue. On an agent’s own entity it is that agent’s size, which the others avoid.
| Prop | Type | Default | Description |
|---|---|---|---|
radius |
number | 0.5 |
Agents keep this far from its centre on the ground plane, in metres. |
It is not a physics collider: nothing is blocked; agents choose to go round. Avoid steers round it, and Flock’s separation keeps off it.
Examples
Section titled “Examples”1. Flee when the wolf howls
Section titled “1. Flee when the wolf howls”#pragma lifecycle(startup)
function startup() { const flee = new SteeringFleeComponent({ target: 'Wolf', panicDistance: 12, weight: 3 }); self.parent.addComponent(flee); flee.setEnabled(false);
on('wolf/howl', () => flee.setEnabled(true)); on('wolf/gone', () => flee.setEnabled(false));}Six wandering, flocking sheep each get a Steering Flee from a script, disabled until the wolf howls: then fleeing outweighs the other behaviours and the flock scatters.
Press Howl: the sheep run from the amber wolf until they are 12 m away. Press Wolf leaves and they drift back together. Drag to orbit the camera, scroll to zoom.
The script adds a Flee behaviour at runtime, aimed at the entity named Wolf, and keeps it disabled until the wolf howls. With weight: 3, fleeing outweighs the wander and flock behaviours (weight 1 each) while the wolf is within 12 m, so the sheep scatter, then drift back together once it is switched off.
2. A guard that spots and chases the player
Section titled “2. A guard that spots and chases the player”#pragma lifecycle(startup, update)
const SIGHT = 15; // metresconst ALERT_SPEED = 6; // metres per secondconst PATROL_SPEED = 2;
let pursue;let patrol;let character;let chasing = false;const me = new THREE.Vector3();const player = new THREE.Vector3();
function startup() { // The guard: Character Controller (controls: false), Steering Agent with // viewDistance 15 and viewAngle 120, a Steering Follow Path (repeat: 'repeat') // and a Steering Pursue with weight 0. character = self.parent.getComponent(CharacterControllerComponent); patrol = self.parent.getComponent(SteeringFollowPathComponent); pursue = self.parent.getComponent(SteeringPursueComponent); if (CameraDirector.main) pursue.setProps({ target: CameraDirector.main });}
function update() { if (!CameraDirector.main) return; self.parent.getWorldPosition(me); CameraDirector.main.getWorldPosition(player); const near = me.distanceTo(player) < SIGHT; if (near === chasing) return;
chasing = near; pursue.setProps({ weight: chasing ? 2 : 0 }); patrol.setProps({ weight: chasing ? 0 : 1 }); character.setProps({ speed: chasing ? ALERT_SPEED : PATROL_SPEED }); emit(chasing ? 'guard/alert' : 'guard/calm');}A guard patrols a loop with Steering Follow Path; when the camera comes within 15 m, the script hands over to Steering Pursue and speeds it up, and an Enable On Signal lights its alarm.
Scroll in to bring the camera closer than 15 m: once the guard faces you, it runs at you. Scroll out to let it return to its patrol. Drag to orbit the camera.
The guard patrols a looping path. Pursue is present from the start but has weight 0, so it does nothing. When the player comes within 15 m, the script swaps the weights so pursuit takes over, and speeds the Character Controller up. Because the Steering Agent has a 120° viewAngle, Pursue only reacts once the player is actually in front of the guard: sneaking up from behind works. The script changes props only when the state flips.
3. Give an agent a route at runtime
Section titled “3. Give an agent a route at runtime”#pragma lifecycle(startup)
const STOPS = ['Bakery', 'Fountain', 'Library'];
function startup() { const route = STOPS.map((name) => { const p = findEntity(name).position; return [p.x, p.y, p.z]; }); const path = new SteeringFollowPathComponent({ points: route, repeat: 'once', radius: 0.8 }); self.parent.addComponent(path);
on('courier', (event) => { if (event.eventType !== EventType.SteeringAgent.Arrive) return; log('Delivery round finished at', event.data.position); delay(() => path.restart(), 5000); });}A script turns three landmarks into a Steering Follow Path for a courier; at the last stop the Steering Agent sends arrive, and the round starts again five seconds later.
Watch the amber courier visit the bakery, the fountain and the library in order; at the library the log reports the round, and the next one starts after five seconds. Drag to orbit the camera, scroll to zoom.
The script turns the positions of three named landmarks into a list of [x, y, z] points and gives the courier a Follow Path with them. At the last point, the Steering Agent sends SteeringAgent::arrive. The script waits five seconds with delay, then calls restart() to begin the round again from the first point. This assumes the landmarks sit directly under the scene root, so their position is a world position.
4. A flock that follows a leader and avoids crates
Section titled “4. A flock that follows a leader and avoids crates”#pragma lifecycle(startup)
const BIRDS = ['Bird 1', 'Bird 2', 'Bird 3', 'Bird 4', 'Bird 5'];
function startup() { for (const name of BIRDS) { const bird = findEntity(name); if (!bird) continue; bird.addComponent(new SteeringFollowLeaderComponent({ leader: 'Leader', distance: 2.5 })); bird.addComponent(new SteeringFlockComponent({ radius: 4, separation: 2 })); bird.addComponent(new SteeringAvoidComponent({ lookAhead: 4 })); } // Crates are obstacles the birds steer round. for (const crate of ['Crate A', 'Crate B']) { findEntity(crate)?.addComponent(new SteeringCollidableComponent({ radius: 1 })); }}A script gives five steering agents Follow Leader, Flock and Avoid behaviours, and two crates a Steering Collidable, so the flock trails a wandering leader round the crates.
Watch the blue flock follow the amber leader. Drag to orbit the camera, scroll to zoom.
Each bird (a plain object already carrying a Steering Agent, with no Character Controller) gets three behaviours: follow the entity named Leader, flock with its neighbours, and avoid obstacles. The crates get a Steering Collidable so Avoid and Flock’s separation keep the birds off them. Creating behaviours from code is useful for spawned crowds; for hand-placed agents, add the same components in the editor.
5. Show an agent’s speed
Section titled “5. Show an agent’s speed”#pragma lifecycle(startup, update)
let agent;let label;let shown = '';
function startup() { agent = self.parent.getComponent(SteeringAgentComponent); label = findEntity('Speed Label').getComponent(TextComponent);}
function update() { const v = agent.velocity; const text = `${Math.hypot(v.x, v.z).toFixed(1)} m/s`; if (text === shown) return; shown = text; label.setProps({ text });}A wandering Steering Agent's velocity is shown as a speed on a Text sign, updated only when the rounded value changes.
Watch the speed change as the agent wanders, speeds up and turns. Drag to orbit the camera, scroll to zoom.
velocity is the agent’s current ground-plane velocity. The script shows its length as a speed in a text label, updating the label only when the rounded value changes. It is a quick way to tune maxForce, mass and the behaviours’ weights.
Common mistakes
Section titled “Common mistakes”- The agent does not move. Check that a behaviour has a target that exists and a non-zero weight, and, if the agent has a Character Controller, that it has
controls: falseand is enabled (disabling it pauses steering). - Agents ignore a target behind them. With a
viewDistance, they only see inside theirviewAngle. Use0to see at any distance. - Expecting a Steering Collidable to block. It is advice, not physics. Add a collider for a real wall.
- Agents walk through walls. Steering is straight unless there is a NavMesh Agent. Add one, or Avoid with Steering Collidables.
- Path points relative to the agent. Follow Path points are world-space.
moveTofreezes the behaviours. A Character ControllermoveTopauses steering until it arrives or you callstop().