AI System

Table of Contents

Overview

RCCP includes a waypoint-based AI driving system that can autonomously control vehicles. The AI driver (RCCP_AI) uses NavMesh pathfinding, PID-based throttle/brake control, and look-ahead steering to navigate waypoints, follow targets, or chase opponents.

AI vehicles use the same physics and drivetrain as player vehicles — they send inputs through the same RCCP_Input override system, so AI cars behave identically to player-driven cars.

AI Behavior Modes

ModeDescription
FollowWaypointsLoops through a waypoint path at normal speed, maintaining safe cornering speeds
RaceWaypointsAggressively races through waypoints, pushing closer to the speed limit in corners
FollowTargetFollows behind a target Transform at a configurable distance
ChaseTargetPursues and attempts to intercept a moving target using prediction

Editable in Lite

ParameterDescription
behaviourSelect one of the four behavior modes

Locked in Lite (Available in Pro)

Waypoint container assignment, target references, look-ahead distances, road grip factor, max throttle/brake, aggressiveness, steer sensitivity, PID gains (kp, ki, kd), follow distance, prediction time, waypoint reach threshold.

Setting Up AI Waypoints

AI vehicles need a waypoint path to follow. To create one:

  1. In the Unity menu, go to Tools > BoneCracker Games > RCCP > Create > Add AI Waypoints
  2. This creates an RCCP_AIWaypointsContainer GameObject in your scene
  3. Add child GameObjects as individual waypoints (RCCP_Waypoint), positioning them along the desired driving path
  4. The AI will follow waypoints in order, looping back to the first when it reaches the last

Waypoint Tips

Brake Zones

For more realistic AI behavior, you can add brake zones that tell the AI to decelerate before sharp corners:

  1. Tools > BoneCracker Games > RCCP > Create > Add AI Brake Zones
  2. Creates an RCCP_AIBrakeZonesContainer
  3. Position brake zone triggers before corners

The AI automatically calculates safe cornering speeds based on the road grip factor and turn angle, but explicit brake zones provide additional control.

Dynamic Obstacle Avoidance

The RCCP_AIDynamicObstacleAvoidance component (optional) adds real-time obstacle detection using raycasts. When the AI detects an obstacle ahead, it steers to avoid it. This handles unexpected objects that aren't part of the waypoint path, such as other vehicles, pedestrians, or debris.

How AI Driving Works

Steering

The AI uses look-ahead steering — it aims toward a point ahead of the vehicle on the waypoint path rather than directly at the current waypoint. The look-ahead distance increases with speed:


lookAheadDistance = minLookAhead + (speed * lookAheadPerKph)

This produces smooth, natural-looking steering rather than jerky corrections.

Throttle and Brake

The AI uses a PID controller to regulate speed:

The desired speed is calculated based on the angle of the upcoming turn — sharper turns get lower target speeds.

Stuck Detection

The AI monitors whether it's making forward progress. If the vehicle gets stuck (speed near zero for too long), it applies corrective actions: reverse, steer, and attempt to get unstuck.

Creating an AI Vehicle

To make a vehicle AI-controlled:

  1. Ensure the vehicle has an RCCP_AI component (under RCCP_OtherAddons)
  2. Set externalControl = true on the RCCP_CarController
  3. Assign a waypoint container to the AI component (Pro), or use runtime API
  4. The AI will override the vehicle's input when active

Via Script


// Spawn an AI vehicle
RCCP_CarController aiVehicle = RCCP.SpawnRCC(
    vehiclePrefab,
    spawnPosition,
    spawnRotation,
    registerAsPlayer: false,
    isControllable: false,
    engineRunning: true
);

// The AI component auto-activates when externalControl is true
RCCP.SetExternalControl(aiVehicle, true);

AI and Player Vehicles Together

You can have both player and AI vehicles in the same scene. The RCCP_SceneManager tracks all vehicles in its allVehicles list. Only the registered player vehicle responds to player input; all others can be AI-controlled.


// Get all vehicles in the scene
List<RCCP_CarController> allCars = RCCP_SceneManager.Instance.allVehicles;

// Only the active player vehicle responds to player input
RCCP_CarController playerCar = RCCP_SceneManager.Instance.activePlayerVehicle;

Next Steps