Loading...
 
Send a link

AI

This component is the brain of the vehicle, it is the component which will decide how much throttling, braking and steering must be applied at each point of the track. As the vehicle behaviour can be very different for different vehicle Physics, we will use a different script for each of the supported vehicle Physics. In general terms, we will create an AI-controlled vehicle using exactly the same procedure than we use for creating a player-controlled vehicle, but changing one of the scripts attached to the vehicle GameObject:

AI Components
Vehicle Physics This script should be added to the vehicle GameObject... ...instead of the following script(s)
Edy's Vehicle Physics ProRacingAI / EdyVehiclePhysics / AI4EdyVehiclePhysics.js  
UnityCar ProRacingAI / UnityCar / AI4UnityCar.cs  UnityCarScripts / AxisCarController.cs
UnityCarScripts / MouseCarController.cs
Unity Tutorial (Simple Physics) ProRacingAI / UnityTutorial / SimplePhysics / AI4UnityTutorial.js Scripts / Javascript / Car.js
Unity Tutorial (Alternate Physics) ProRacingAI / UnityTutorial / AlternatePhysics / AI4UnityTutorial.cs ~AlternatePhysicsModel / Scripts /  CarController.cs

When using Edy's Vehicle Physics, the External Input toggle from the CarSettings class should be enabled for AI-controlled vehicles and disabled for player-controlled vehicles. When using UnityCar, the Enable Keys toggle from the AI4UnityCar class should be disabled.

 

Contents

AI Parameters

As the AI component is tightly integrated with the underlying vehicle Physics , each AI script will have some common paramers and other parameters that are specific for each vehicle Physics.

These common parameters are:

  • Track Information: it is the text file where the information about the racing line was saved. While similar vehicles can share the same Track Information file, vehicles with a very different behaviour should probably use different Track Information files.
  • Distance: this parameter tells Pro Racing AI if distances from the racing line to the border of the tracks should be measured in a 3D space or in 2D space (XZ plane). 2D measures are usually more forgiving with zones where the racing line information doesn't match the real shape of the track, but 3D measures can give better results in some cases.
  • Vehicle Size: the length (in meters) of the vehicle. It is used to check if the vehicle is too close to the track limits.
  • Margin of Error: this is the max error (in meters) that can be committed in the calculation of the nearest position in the racing line. Lower error values will make the AI drive better, but they will increase the memory consumption.

Driver Traits

It isn't uncommon that we want to define a different behaviousr for several AI vehicles that share the same racing line. In these situations, we can use the driver traits parameters to modify the default behaviour of one or more AI controlled vehicles. These parameters usually have a value in the (0...1) range, but it's possible to use lower or higher values to obtain the desired behaviour.

  • Speed: this parameter is tightly related to the grip parameter of the racing line. Higher values make the AI drive faster, specially in the slowest parts of the track.
  • Aggressiveness: this parameter is tightly related to the deceleration parameter of the racing line. Higher values make the AI brake later (and harder) while low values make the AI start braking sooner
  • Anticipation: this parameter is tightly related to the look ahead parameter of the racing line. Higher values make the AI start turning sooner while low value make the AI don't turn until the last moment.
  • Steering sensibility: this parameter is used for calculating how much steering should be applied.
  • Drift Threshold: this parameter is used for calculating how much drift should have the vehicle before the AI start the counter-steering maneuver. This parameter is measured in degrees between the velocity vector and the forward vector of the vehicle.
  • Drift Braking: this parameter is used for calculating the throttling and braking during counter-steering maneuvers.
  • Drift Steering: this parameter is used for calculating how much steering will be applied during counter-steering maneuvers.
  • Avoid Track Limits: if this checkbox is enabled, the AI will try to come back to the racing line if it gets too close to the track limits, braking and steering harder than usual if necessary.
  • Track Limits Braking: when the Avoid Track Limits checkbox is enabled, this parameter is used for calculating the throttling and braking that must be applied when the AI is too close to the track limits.
  • Track Limits Steering: when the Avoid Track Limits checkbox is enabled, this parameter is used for calculating the steering that must be applied when the AI is too close to the track limits.

Respawn Parameters

These parameters are used to respawn the AI vehicle in the nearest position of the racing line under certain circunstances:

  • Respawn Out of Limits: if this checkbox is enabled, the vehicle will respawn whenever it crosses the "red line" defined by the Left Wall and Right Wall distances of the racing line.
  • Allow Shortcuts: if this parameter is enabled, the AI can take any existing shortcut as long as it doesn't cross any "red line".
  • Respawn on Stuck: if this checkbox is enabled, the AI the vehicle will respawn if it gets stuck.
  • Max Respawn Speed: the vehicle will be considered stuck if its speed is lesser than this value (km/h)..
  • Time Till Respawn: how much time (in seconds) must remain the AI stuck until the vehicle respawn.
  • Respawn Height Offset: how much meters above the racing line will be respawned the vehicle.

 

BACK