Below is a comprehensive documentation for the ContextSteering script. You can use this documentation as a reference to understand its purpose, configuration, and inner workings.
The ContextSteering script is a Unity MonoBehaviour component designed for vehicle AI. It implements a context-based steering system that helps a vehicle determine the best steering direction by evaluating multiple potential directions. This evaluation considers the target direction, obstacles, and the presence of other vehicles. The script uses sphere casts to detect obstacles and dynamically calculates “interest” (how much a given direction aligns with the goal) and “danger” (how much an obstacle or other vehicle interferes with that direction). It then combines these factors to decide on an optimal steering direction.
Adding Context based Steering Script :
You can add this script by right clicking on Ai Vehicle Controller Script and selecting Add Context based Steering Option. (you can also remove it using Remove Context Based Steering Option)
Steering Settings:
AnimationCurve
that modulates the effective ray length based on the vehicle’s velocity alignment with each direction.obstacleLayers
and otherVehicleLayers
are used to filter the sphere casts for obstacles and other vehicles respectively.Weights:
Adjust the following weights to balance between reaching the target and avoiding hazards:
targetWeight
: How strongly the vehicle should favor the target direction.obstacleWeight
: The penalty factor applied for nearby obstacles.otherVehiclesWeight
: The penalty for detecting other vehicles.inertiaWeight
: How much the vehicle’s current velocity influences its steering decision.Vehicle Dimensions and Obstacle Settings:
vehicleRadius
: Represents the vehicle’s size; used in sphere casts to simulate the vehicle’s width.obstacleCloseDistance
: Defines a threshold distance to consider an obstacle “very close”, potentially triggering immediate avoidance maneuvers.lookAheadFactor
: Multiplies the vehicle’s current speed to extend detection range in the movement direction.Gizmo Settings:
Enable or disable gizmo visualizations such as interest levels, danger levels, and the best direction for debugging purposes.