AI Racer Setup
Last updated
Last updated
An important step in creating a functional AI is making sure it receives all the information it needs.
Add the "Raycast Sensor Debugger" component. This component will display what information the AI will receive.
Add the reference to the "Raycast Sensor" component:
Enable Gizmos and modify the properties to your needs:
You can think of these rays as a field of view of the AI. The range of the decisions an AI can make depends on the number and angle between the rays, so make sure the overall angle between left and rightmost rays is big enough.
Rear Ray Length should be just a little behind the car so that the AI knows it can't go in that direction.
Next, create a new layer and assign it to potential obstacles the AI must know of. Create "Obstacle" and "Vehicle" layers.
Assign the "Vehicle Layer" to the game object with the collider on the vehicle.
Assign the "Obstacle" layer to any stationary object that the AI must know of.
In the "Raycast Sensor" component, add the recently created layer to the "Collision Layer" property:
To configure the racer's behavior you can modify the following properties:
Property | Description |
---|---|
AI Interest Modifier
Defines how close the car wants to stay to the track. Higher values reduce the interest of going into any direction except the closest one. Very high values can cause the vehicle to ignore possible collisions.
AI Danger Modifier
Defines how dangerous the AI will treat the collisions that are not in its way. Higher values reduce the danger of possible side collisions
Riskiness
Defines how close the possible collision must be for AI to take extreme action to avoid it. Danger is defined as a dot product between the vehicle's forward axis and the danger direction. If dot product is higher than risk, the AI will brake and steer away from danger