AI System

This document covers RCC's built-in AI driver: how it works, how to add AI vehicles to your scene, how to lay out waypoint paths for them to follow, and how to tune the AI for different driving styles (race opponents, traffic, chase vehicles).

The AI system is a useful starting point that handles the common cases. If you need radically different AI behavior (formation driving, swarm AI, advanced racing line optimization), you'll probably want to build on top of 17 — Overriding Inputs instead.

How RCC AI Works

RCC_AICarController is a MonoBehaviour you add to a vehicle. Each frame, it:

  1. Looks at the next waypoint to drive toward.
  2. Computes the heading angle from the vehicle to the waypoint.
  3. Sets steerInput to turn toward the waypoint.
  4. Sets throttleInput based on distance and current speed.
  5. Slows down if the next waypoint is at a sharper angle than the vehicle can handle.
  6. Calls OverrideInputs() on the parent vehicle controller.

This is the same OverrideInputs path you'd use for your own custom AI — the built-in AI just does the math for you.

The AI also handles:

AI Driving Modes

The AI has three top-level modes, switched via the Navigation Mode enum on RCC_AICarController:

Following Waypoints

The default mode. The AI cycles through waypoints in a RCC_AIWaypointsContainer in order. When it reaches a waypoint, it advances to the next. At the last waypoint, it loops back to the first (for a closed track) or stops (for a one-way path, configurable).

Use this for traffic AI (AI cars driving around a city) and race opponents.

Chase Player

The AI ignores waypoints and instead drives toward the active player vehicle. It uses the same steering and throttle logic but its target is the player rather than a static waypoint.

Use this for chase scenarios — police pursuit, enemies, etc.

Random

The AI ignores waypoints and chooses a random direction every few seconds. Useful for panicked NPCs or wildlife-like behavior.

Adding an AI Vehicle to a Scene

The fastest path:

Step 1 — Drag In an AI-Configured Prefab

Use Prefabs/Vehicles/Skyline (AI Chaser).prefab — it's pre-configured as an AI vehicle. Drag it into your scene.

Step 2 — Configure the Target

Click the AI vehicle. In its RCC_AICarController Inspector:

Step 3 — Press Play

The AI vehicle should start driving along your waypoints automatically.

Building a Waypoint Path

A waypoint path is a list of empty GameObjects in the scene, each marking a position the AI should drive to. They live as children of a container GameObject that holds the RCC_AIWaypointsContainer component.

Add a Waypoint Container

Menu: Tools → BoneCracker Games → Realistic Car Controller → Create → Add AI Waypoints Container To Scene.

A new GameObject called RCC_AIWaypointsContainer appears in the Hierarchy with the container component on it.

Add Waypoints

  1. Select the container.
  2. In the Inspector, click Add Waypoint (or use the in-scene controls).
  3. Move the new waypoint to where you want it. The waypoints are typed as RCC_Waypoint — small markers with a position and an optional target speed.
  4. Repeat to build the path.

Each waypoint has:

For a racing track, set targetSpeed to a high value (e.g., 200) on straights and a lower value (e.g., 60) on sharp turns. The AI will slow down naturally for the corners.

Path Layout Tips

Brake Zones

Sometimes the AI needs to slow down beyond what the waypoint target speeds suggest — e.g., a sharp blind corner. A brake zone is a trigger volume that forces the AI to brake while inside.

Add a Brake Zone Container

Menu: Tools → BoneCracker Games → Realistic Car Controller → Create → Add AI Brake Zones Container To Scene.

Add Brake Zones

The container holds individual RCC_AIBrakeZone triggers. Each brake zone is a box-shaped trigger volume.

  1. Select the container.
  2. Click Add Brake Zone (or place a child GameObject yourself with RCC_AIBrakeZone and a BoxCollider set to trigger).
  3. Resize the box collider to cover the area where AI should brake.
  4. Set the brake zone's Target Speed — what speed the AI should target while inside.

Place brake zones at:

Configuring AI Behavior

The RCC_AICarController component has many tunables. The most useful:

Speed

Steering

Brake

Obstacle Avoidance

Stuck Detection

Chase Mode

For police / enemy / hunter AI:

  1. Set Navigation Mode to Chase Player.
  2. The AI automatically targets the active player vehicle (RCC_SceneManager.Instance.activePlayerVehicle).
  3. No waypoints needed — chase ignores them.

If you want the AI to chase a specific vehicle (not the registered player), set the Target Chase field on RCC_AICarController to that vehicle's RCC_CarControllerV4.

For more aggressive chase behavior, set:

Race Mode

For racing opponents:

  1. Use Following Waypoints mode.
  2. Build a closed loop of waypoints around your track.
  3. Set high targetSpeed values on straights, low values at corner entries.
  4. Add brake zones at the slowest turns for extra safety.
  5. Tune Steering Speed higher (10–12) for snappy turn-ins.

Multiple AI Vehicles

You can have many AI vehicles in a scene. Performance depends on:

A typical desktop game can handle 30–50 AI vehicles. Mobile drops to 5–15 depending on the device.

Spawning AI Programmatically

public class SpawnTraffic : MonoBehaviour {
    public RCC_CarControllerV4 trafficVehiclePrefab;
    public RCC_AIWaypointsContainer waypoints;
    public Transform[] spawnPoints;

    void Start() {
        for (int i = 0; i < spawnPoints.Length; i++) {
            RCC_CarControllerV4 vehicle = RCC.SpawnRCC(
                trafficVehiclePrefab,
                spawnPoints[i].position,
                spawnPoints[i].rotation,
                registerAsPlayerVehicle: false,
                isControllable: false,
                isEngineRunning: true);

            RCC_AICarController ai = vehicle.GetComponent<RCC_AICarController>();
            ai.waypointsContainer = waypoints;
            ai.navigationMode = RCC_AICarController.NavigationMode.FollowWaypoints;
        }
    }
}

(Exact field names may vary — check RCC_AICarController.cs for your version.)

AI Events

Subscribe to AI spawn/destroy via RCC_Events:

void OnEnable()  { RCC_Events.OnRCCAISpawned += HandleAISpawned; }
void OnDisable() { RCC_Events.OnRCCAISpawned -= HandleAISpawned; }

void HandleAISpawned(RCC_AICarController ai) {
    // Add to a minimap, hostile list, etc.
}

See 24 — Events System.

Custom AI

If you need behavior the built-in AI doesn't support, don't modify RCC_AICarController — write your own AI script and use Override Inputs. See 17 — Overriding Inputs for the pattern.

A custom AI script lives alongside your vehicle. It can:

Your custom AI plays nicely with everything else (events, damage, customization) because the underlying vehicle is still standard RCC.

Common AI Issues

"AI ignores my waypoints"

Check that the AI vehicle's Waypoints Container field is assigned. Also check that Navigation Mode is set to Following Waypoints.

"AI keeps driving in circles around a waypoint"

The waypoint's Pass Radius is too small — the AI thinks it's not close enough and keeps trying to approach. Increase the pass radius to 8–15 m.

"AI rams into walls at corners"

Either the waypoint at the corner is too aggressive (targetSpeed is too high) or the AI doesn't have enough lookahead. Add a brake zone before the corner, or increase Lookahead Distance.

"AI cars get stuck on each other"

Multiple AI vehicles all chasing the same waypoint can collide. The built-in obstacle avoidance helps but isn't perfect. For dense traffic, consider lower max speed, lower steering speed, and slightly offset waypoints per vehicle.

"AI keeps spinning out"

The AI's friction tuning may not match the player's. Try setting the AI vehicle's Override Behavior flag to true and configuring per-vehicle friction values manually. Or reduce Steering Speed so the AI doesn't snap the wheel.

"Chase AI loses the player"

The AI's Max Speed is lower than the player's. Increase it. Or check that Target Chase points to the right vehicle (active player or a specific one).

Next Steps