Steering Behaviors and Flocking

Updated June 2026
Steering behaviors are the algorithms that make NPC movement look natural rather than robotic. Introduced by Craig Reynolds in 1987, they work by generating force vectors that nudge an agent's velocity toward desired movement patterns like seeking a target, avoiding obstacles, or staying in formation with a group. Combined with flocking rules, they produce the emergent group movement seen in everything from bird simulations to squad-based tactical games.

Pathfinding tells an NPC where to go. Steering behaviors tell it how to move. Without steering, an NPC following a pathfound route would snap instantly between waypoints or move in rigid straight lines with sharp 90-degree turns. Steering behaviors transform that mechanical movement into smooth curves, gradual turns, and responsive adjustments that make the NPC feel like a physical entity with mass and momentum. This distinction between strategic navigation (pathfinding) and tactical movement (steering) is fundamental to believable AI movement in games.

Step 1: Implement Basic Steering Forces

Every steering behavior produces a force vector, a direction and magnitude that the agent should accelerate toward. The agent has a position, a velocity, a maximum speed, and a maximum force (which limits how sharply it can turn or accelerate). Each frame, the steering force is added to the current velocity (clamped to maximum force), the velocity is clamped to maximum speed, and the position is updated by the velocity.

Seek is the simplest steering behavior. Calculate the desired velocity as the vector from the agent's position to the target's position, normalized and scaled to maximum speed. The steering force is the difference between the desired velocity and the current velocity. This produces a smooth curve toward the target because the agent does not instantly change direction but gradually adjusts its heading. The result looks like a homing missile or a predator curving toward prey.

Flee is the inverse of seek. The desired velocity points away from the threat rather than toward it. The steering force again is desired velocity minus current velocity. Flee produces a smooth curve away from the threat with the same natural-looking motion as seek.

Arrive is seek with deceleration. Without arrive, an NPC seeking a target will overshoot it, then turn around and overshoot again, oscillating forever. Arrive adds a deceleration radius around the target. When the agent is outside this radius, it behaves like seek at full speed. When inside, the desired speed scales linearly with distance, so the agent decelerates smoothly to a stop exactly at the target. The deceleration radius should be tuned based on the agent's maximum speed and turning rate so the braking looks natural.

Pursue is seek aimed at where the target will be rather than where it is now. The agent estimates the target's future position based on its current velocity and the time it would take to reach it, then seeks that predicted position. This produces much more effective interception behavior because the pursuer cuts off the target rather than chasing its trail. Evade is the flee version of pursue, predicting the threat's future position and fleeing from it.

Step 2: Add Wander and Obstacle Avoidance

Wander produces natural-looking random movement without the jittery direction changes that come from picking a new random heading each frame. Reynolds' wander works by projecting a circle in front of the agent and placing a target point on the circumference of that circle. Each frame, the target point moves a small random amount around the circle's edge. The agent seeks this target point. Because the target can only shift slightly between frames, the resulting movement is smooth and flowing with gentle, organic curves.

The wander circle has two parameters: its distance from the agent (how far ahead the circle is projected) and its radius (how wide the direction changes can be). A small radius with a large distance produces gentle, sweeping curves suitable for birds or fish. A large radius with a small distance produces tighter, more erratic movement suitable for insects or nervous animals. Tuning these two numbers gives you a wide range of movement personalities.

Obstacle avoidance prevents agents from colliding with walls and static geometry. The basic approach casts one or more rays ahead of the agent in its direction of travel. If a ray detects an obstacle within a threshold distance, the behavior generates a lateral steering force that pushes the agent away from the obstacle. The force magnitude increases as the obstacle gets closer, creating a smooth swerving motion rather than a last-second dodge.

A single forward ray works for simple environments but fails when obstacles approach from an angle. Using three rays (forward, forward-left, forward-right) or a whisker arrangement gives much better coverage. The angle between rays should match the agent's width so it detects obstacles that its body would actually collide with. For agents moving at high speeds, the ray length should increase proportionally because the agent needs more distance to steer around obstacles before reaching them.

Step 3: Combine Forces with Weighting

Real NPC movement usually requires multiple steering behaviors active simultaneously. A soldier might need to arrive at a waypoint while avoiding obstacles and maintaining distance from allies. Each behavior produces its own force vector, and these vectors must be combined into a single resultant force that the agent actually applies.

Weighted blending multiplies each behavior's force by a weight (reflecting its importance) and sums all the weighted forces. The total is then clamped to the agent's maximum force. This is simple to implement and tune. Obstacle avoidance might have a weight of 3.0 while wander has a weight of 0.5, ensuring collision prevention always dominates idle movement. The drawback is that a strong low-priority force can partially cancel a weak high-priority force, which can cause collisions in extreme cases.

Priority-based truncation evaluates behaviors in priority order. The highest-priority behavior's force is applied first. If force budget remains (the total has not reached maximum force), the next behavior's force is added, and so on until the budget is exhausted. This guarantees that high-priority behaviors like obstacle avoidance always get their full force applied. Lower-priority behaviors only influence movement when higher-priority behaviors do not need the full force budget.

Context steering is a more recent approach that represents each behavior's preferences as a ring of direction slots rather than a single force vector. Each behavior votes for or against each direction slot. The final movement direction is the slot with the highest combined vote. Context steering handles competing requirements more gracefully than vector addition because it can represent "I want to go forward but not through that wall" as separate votes rather than opposing forces that cancel each other out.

Step 4: Implement Flocking Rules

Craig Reynolds' flocking model uses three simple rules that, when combined, produce remarkably lifelike group movement. Each rule generates a steering force, and these forces are weighted and summed with any other active steering behaviors.

Separation steers each agent away from nearby neighbors to prevent crowding and collision. For each neighbor within a defined radius, calculate the vector pointing away from that neighbor, weighted by the inverse of the distance (closer neighbors produce stronger repulsion). Sum all these vectors to get the separation force. Without separation, agents pile on top of each other. Separation is typically the highest-weighted flocking force because overlap looks obviously wrong.

Alignment steers each agent to match the heading of nearby neighbors. Calculate the average velocity of all neighbors within a defined radius, then steer toward that average. Alignment is what makes a flock turn in unison, each agent gradually adjusting to match the group's heading. Without alignment, a group that is merely separated and cohesive would drift apart randomly because individuals have no reason to move in the same direction.

Cohesion steers each agent toward the center of nearby neighbors. Calculate the average position of all neighbors within a defined radius, then seek that position. Cohesion pulls the group together, counteracting the outward push of separation. The balance between separation and cohesion determines how tightly packed the group is: high cohesion with low separation produces dense clusters, while low cohesion with high separation produces loose, spread-out groups.

The neighborhood radius for each rule can be different. Separation usually uses a small radius (agents only avoid immediate neighbors), while alignment and cohesion use larger radii (agents coordinate with more distant group members). Limiting the neighborhood to agents within a forward-facing arc rather than a full circle produces more directional flocking that resembles bird behavior, where individuals pay more attention to flock members ahead of them than behind.

Step 5: Build Formation Movement

Flocking produces organic, loosely structured group movement. For military squads, police patrols, or any group that should maintain a specific shape, formation movement extends flocking principles with assigned positions.

A formation defines a set of slot positions relative to a formation anchor (usually the leader or the group's center of mass). Each slot has a local offset, like "2 meters to the left and 1 meter behind the leader." Each group member is assigned to a slot, and its primary steering behavior is arrive targeted at the world-space position of its assigned slot.

When the formation moves, the anchor moves and all slot positions update accordingly. Each agent steers toward its updated slot position, producing coordinated movement. Separation prevents agents from overlapping while they reposition, and the arrive behavior ensures they decelerate smoothly into their assigned spots.

Dynamic formation reshaping handles narrow passages and obstacles. When the formation detects that its current shape does not fit through an upcoming corridor, it transitions to a column formation (single file) or a compressed variant. After clearing the obstacle, it transitions back to the original shape. The transition should be gradual, with agents smoothly moving to their new slot positions rather than teleporting, so the reformation looks natural and deliberate.

Role-based formations assign specific positions based on NPC capabilities. The toughest unit takes point, ranged units position at the rear, and the medic stays in the center. If a member is eliminated, the formation reshuffles with the remaining members adapting to cover the gap. This kind of responsive formation behavior significantly elevates the perceived intelligence of AI squads.

Step 6: Tune and Debug Movement Quality

Steering behavior systems are entirely parameter-driven, which means they are only as good as their tuning. The same algorithm can produce beautiful, natural movement or jittery, broken movement depending on the force weights, speed limits, and turning rates you choose.

Start by tuning each behavior in isolation. Get seek and arrive working smoothly before adding obstacle avoidance. Get flocking looking natural before combining it with path following. Each behavior introduces its own parameters, and debugging is far easier when you can see the effect of each behavior independently.

Build debug visualization that draws the force vectors for every active behavior on each agent. Use different colors for each behavior type: red for separation, blue for cohesion, green for alignment, yellow for obstacle avoidance. When an agent moves unexpectedly, the visualization immediately shows which force is responsible. Without this visualization, tuning steering behaviors is guesswork.

Watch for common tuning problems. Oscillation happens when opposing forces are too strong relative to the agent's mass, causing it to vibrate rather than settle into a direction. The fix is to add damping or reduce force magnitudes. Wall hugging happens when obstacle avoidance pushes the agent away from a wall but seek or path following pushes it right back, causing it to slide along the wall surface. The fix is to increase the avoidance range so the agent steers away earlier, or use context steering so the agent finds a path around the wall rather than along it. Clumping happens when cohesion is too strong relative to separation, causing all agents to pile into one location. Increase the separation weight or reduce the cohesion weight until agents maintain comfortable spacing.

Steering Behaviors Beyond Movement

While steering behaviors are traditionally associated with physical movement, the same mathematical framework can drive other aspects of NPC behavior. Camera systems use seek and arrive to smoothly follow the player. Attention systems use steering-like forces to smoothly rotate an NPC's gaze between points of interest. Audio systems use arrive-like curves to smoothly transition between music tracks or ambient sound layers. The core concept of generating forces that smoothly blend toward desired states is broadly applicable wherever gradual, natural-looking transitions are needed.

Key Takeaway

Steering behaviors are the low-level movement layer that makes everything above them look good. Pathfinding, behavior trees, and state machines all produce better results when the NPC's physical movement is handled by well-tuned steering behaviors that produce smooth, natural, responsive motion.