Skip to main content

Class SeekBehavior

Steering behaviour that attracts the actor toward a fixed target transform.

public class SeekBehavior : SteeringBehaviour, IHandler

Inheritance​

Implements​

IHandler

Inherited Members​

Examples​

// Without a speed cap (pass a pre-normalized desiredVector to avoid unbounded force):
Vector3 correction = SeekBehavior.Seek(rigidbody.velocity, toTarget.normalized);

// With a speed cap (desiredVector need not be pre-normalized):
Vector3 correction = SeekBehavior.Seek(rigidbody.velocity, toTarget, maxSpeed);

Remarks​

Seek is typically the first behaviour in the SteeringSolver chain because it establishes the goal-directed base vector; subsequent behaviours (obstacle avoidance, flee) then deviate that vector rather than starting from zero. The speed-clamped overload ensures the seek vector never exceeds the actor's maximum speed, preventing over-steering artefacts when the target is very close.

Methods​

GetSteering(Vector3)​

Calculates the steering force to move towards the target.

public override Vector3 GetSteering(Vector3 TargetVector)

Parameters​

NameTypeDescription
TargetVectorVector3The accumulated steering vector passed in from earlier chain nodes.

Returns​

Vector3 — The steering force that will move the object towards the target.

Remarks​

The return value is TargetVector + steering rather than just steering because the chain uses additive composition: each behaviour adds its contribution on top of what the previous nodes produced. Overwriting TargetVector would discard any goal-directed force established earlier in the chain (e.g. a path-following offset), causing those behaviours to have no effect.

Seek(Vector3, Vector3)​

Calculates the steering force without considering max speed.

public static Vector3 Seek(Vector3 velocityVector, Vector3 desiredVector)

Parameters​

NameTypeDescription
velocityVectorVector3The current velocity of the object.
desiredVectorVector3The normalized vector pointing towards the target.

Returns​

Vector3 — The steering vector needed to move towards the target.

Remarks​

The formula desiredVector - velocityVector is Craig Reynolds' steering formula: the desired velocity (direction to target) minus the current velocity equals the corrective force needed to align the actor's motion with that direction. The result is a difference vector — positive when the actor is under-steering and negative when over-shooting — which drives the actor smoothly rather than snapping it to the target. This overload omits the speed cap, so desiredVector should already be normalized before being passed in to prevent unbounded forces at large distances.

Seek(Vector3, Vector3, float)​

Calculates the steering force considering the max speed.

public static Vector3 Seek(Vector3 velocityVector, Vector3 desiredVector, float maxSpeed)

Parameters​

NameTypeDescription
velocityVectorVector3The current velocity of the object.
desiredVectorVector3The vector pointing towards the target.
maxSpeedfloatThe maximum speed the object can move at.

Returns​

Vector3 — The steering force, clamped by the max speed, to move the object towards the target.

Remarks​

This is Craig Reynolds' full steering formula: desiredVelocity = desiredVector.normalized * maxSpeed sets the ideal velocity (full speed toward the target); subtracting the current velocity then gives the corrective force — small when already moving in the right direction, large when heading the wrong way. Clamping the result to maxSpeed prevents the corrective impulse from exceeding the actor's capability, which would cause physically unrealistic instant direction changes.