Class FleeBehavior
Steering behaviour that repels the actor away from a target transform.
public class FleeBehavior : SteeringBehaviour, IHandler
Inheritance
Implements
Inherited Members
- SteeringBehaviour.m_Solver
- SteeringBehaviour.Handle(object)
- SteeringBehaviour.SetNext(IHandler)
- SteeringBehaviour.Start()
- SteeringBehaviour.GetSteering(Vector3)
Remarks
Flee is the inverse of SeekBehavior — it is placed later in the SteeringSolver chain to act as an emergency repulsion layer, typically used when another actor enters an unsafe proximity zone. Because it is additive (the flee vector is added to the incoming chain vector, not substituted), the actor still makes progress toward its goal while veering away from the threat.
Methods
Flee(Vector3, Vector3)
Calculates the steering force to flee from the target, without considering max speed.
public static Vector3 Flee(Vector3 velocityVector, Vector3 desiredVector)
Parameters
| Name | Type | Description |
|---|---|---|
velocityVector | Vector3 | The current velocity of the object. |
desiredVector | Vector3 | The normalized vector pointing towards the threat (object wants to flee from this direction). |
Returns
Vector3 — The steering vector needed to move away from the target.
Remarks
Negating the seek result correctly inverts the Reynolds formula: the desired velocity flips from pointing toward the threat to pointing away from it. Subtracting the current velocity from that inverted desired velocity then produces a corrective force that pushes the actor in the opposite direction. This preserves all the smooth-steering properties of the base formula while reversing the goal direction.
Flee(Vector3, Vector3, float)
Calculates the steering force to flee from the target, considering the max speed.
public static Vector3 Flee(Vector3 velocityVector, Vector3 desiredVector, float maxSpeed)
Parameters
| Name | Type | Description |
|---|---|---|
velocityVector | Vector3 | The current velocity of the object. |
desiredVector | Vector3 | The vector pointing towards the threat (object wants to flee from this direction). |
maxSpeed | float | The maximum speed the object can move at. |
Returns
Vector3 — The steering force, clamped by the max speed, to move away from the target.
Remarks
Negating the speed-capped seek result inverts the Reynolds desired-velocity vector:
instead of desiredVector.normalized * maxSpeed pointing toward the threat, the
actor targets full speed in the opposite direction. The subsequent subtraction of the
current velocity and the magnitude clamp to maxSpeed then produce a
smooth, physically bounded corrective force that pushes the actor away from the threat.
GetSteering(Vector3)
Calculates the steering force to move away from the target.
public override Vector3 GetSteering(Vector3 TargetVector)
Parameters
| Name | Type | Description |
|---|---|---|
TargetVector | Vector3 | The accumulated steering vector passed in from earlier chain nodes. |
Returns
Vector3 — The steering force that will move the object away from the target.
Remarks
The return value is TargetVector + steering for the same reason as
Vector3): additive composition preserves the
goal-directed force from earlier chain nodes. The flee vector is added on top so
the actor continues progressing toward its goal while simultaneously veering away
from the threat.
Note: because the flee contribution is additive and is placed after seek in the
chain, the combined vector's magnitude may exceed MaxSpeed in high-threat
scenarios where the flee and seek forces point in similar directions.
Whether this is acceptable depends on whether SteeringSolver clamps the final vector before applying it to the Rigidbody. If it does not, this is an intentional design choice that allows urgency to temporarily override the speed cap; if it does, the behaviour is implicitly safe.