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:
- Looks at the next waypoint to drive toward.
- Computes the heading angle from the vehicle to the waypoint.
- Sets
steerInputto turn toward the waypoint. - Sets
throttleInputbased on distance and current speed. - Slows down if the next waypoint is at a sharper angle than the vehicle can handle.
- 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:
- Brake zones — pre-placed triggers in the scene that force the AI to slow down regardless of waypoint distance.
- Obstacle avoidance — raycasts from the front of the vehicle that detect obstacles and steer around them.
- Mode switching — three modes: Following Waypoints, Chase Player, Random.
- Stuck detection — if the AI hasn't moved in a few seconds, it reverses briefly to free itself.
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:
- Navigation Mode — set to Following Waypoints (or whichever mode you want).
- Waypoints Container — drag in an
RCC_AIWaypointsContainerfrom your scene (see below).
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
- Select the container.
- In the Inspector, click Add Waypoint (or use the in-scene controls).
- 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. - Repeat to build the path.
Each waypoint has:
- Target Speed — the speed the AI should target at this waypoint (km/h).
- Pass Radius — the AI considers itself "at" the waypoint when within this distance. Default 8 m.
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
- Place waypoints in the center of the lane. AI vehicles aim for the waypoint, so off-center waypoints mean off-center driving.
- Space waypoints based on speed. A waypoint every ~20 m is fine for slow streets; every ~50 m for highways. Too many waypoints close together causes the AI to "weave" between them.
- Add waypoints at corner entry, apex, and exit. This gives the AI three reference points around a turn, making it follow a smoother racing line.
- Close the loop for repeating tracks. Place the last waypoint near the first so the loop is seamless.
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.
- Select the container.
- Click Add Brake Zone (or place a child GameObject yourself with
RCC_AIBrakeZoneand a BoxCollider set to trigger). - Resize the box collider to cover the area where AI should brake.
- Set the brake zone's Target Speed — what speed the AI should target while inside.
Place brake zones at:
- Corner entries.
- Areas before pedestrian crossings.
- Hairpin turns where you want extra slowdown beyond waypoint targets.
Configuring AI Behavior
The RCC_AICarController component has many tunables. The most useful:
Speed
- Max Speed — top speed the AI will target. Default 100 km/h. Lower for traffic, higher for racing.
- Min Speed — minimum speed in normal driving. The AI won't slow below this unless it's stopping for an obstacle.
Steering
- Steering Speed — how fast the AI can rotate the wheel. Higher = snappier corner entry. Default 8.
- Detect Steering Helper — when on, the AI uses RCC's steering helper to smooth its inputs (matches the player feel).
Brake
- Brake Threshold Speed — speed delta that triggers braking. If the AI is going much faster than the target, it brakes hard.
- Lookahead Distance — how far ahead the AI checks for upcoming sharp turns. Higher = anticipates earlier, brakes earlier.
Obstacle Avoidance
- Use Obstacle Avoidance — toggle the raycast-based avoidance.
- Ray Distance — how far ahead obstacle rays cast. Default 5 m.
- Raycast Layers — which layers to count as obstacles.
Stuck Detection
- Stuck Time — seconds of no movement before reversing. Default 3.
- Reverse Time — how long to reverse before trying forward again. Default 1.5.
Chase Mode
For police / enemy / hunter AI:
- Set Navigation Mode to Chase Player.
- The AI automatically targets the active player vehicle (
RCC_SceneManager.Instance.activePlayerVehicle). - 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:
- Aggressive to true.
- Max Speed higher than the player.
- Reduce Brake Threshold Speed (the AI won't slow down for turns as much).
Race Mode
For racing opponents:
- Use Following Waypoints mode.
- Build a closed loop of waypoints around your track.
- Set high
targetSpeedvalues on straights, low values at corner entries. - Add brake zones at the slowest turns for extra safety.
- 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:
- Number of active AI (each runs an Update / FixedUpdate cycle).
- Number of wheel colliders per AI (4 wheels per vehicle).
- Distance from the player (consider LOD for far vehicles).
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:
- Read sensor data (raycasts, physics queries).
- Compute desired inputs via any logic (rule-based, behavior tree, ML model).
- Feed inputs via
OverrideInputs().
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
- 17 — Overriding Inputs — the foundation the AI is built on.
- 24 — Events System — AI events.
- 23 — Scripting API — spawning vehicles at runtime.