Core Behaviors
1. Input Handling
• Accepts player input (throttle, brake, steer, etc.) via RCC_InputManager or can be overridden for AI/external control.
• Supports manual, automatic, and semi-automatic gear shifting.
2. Physics & Dynamics
• Uses Unity’s Rigidbody for physics.
• Manages wheels via custom RCC_WheelCollider components.
• Calculates and applies torque, brake, and steering per wheel.
• Implements anti-roll bars, downforce, and dynamic center of mass adjustment for stability.
3. Driving Assistance
• Features ABS, TCS, ESP, steering/traction helpers, and angular drag helper for realistic handling and safety.
• Drift detection and drift mode support.
4. Engine & Gearbox
• Simulates engine torque curve, RPM, inertia, and rev limiter.
• Handles fuel consumption, engine heat, and turbo/NOS boost.
5. Audio & Visuals
• Dynamically manages engine, wind, brake, and collision sounds.
• Animates steering wheel and manages vehicle lights and indicators.
6. Damage & Collisions
• Supports mesh deformation, collision particles, and crash sounds.
• Can auto-reset if flipped or stuck.
7. Customization & Events
• Integrates with a customizer for visual upgrades.
• Fires events on spawn, destroy, and collision.
Update & FixedUpdate Loops
• Update(): Handles input, audio, visual feedback, and drift logic.
• FixedUpdate(): Manages physics, engine, steering, wheels, driving assists, and applies forces.
Extensibility
• Highly modular: Many features can be toggled or overridden.
• Supports both player and AI control.
---
Summary:
RCC_CarControllerV4 is a feature-rich, modular car controller for Unity, simulating realistic vehicle physics, input, audio, and visual feedback, with extensive support for driving assists, damage, and customization.
1. ABS (Anti-lock Braking System)
• Purpose: Prevents wheel lockup during heavy braking.
• Implementation:
• Controlled by the ABS boolean.
• Threshold: ABSThreshold (default 0.35).
• Behavior:
• When braking, the script monitors wheel slip.
• If slip exceeds ABSThreshold, ABS modulates brake torque to prevent lockup.
• The flag ABSAct is set true when ABS is active.
• Note: The actual modulation logic is likely handled inside the RCC_WheelCollider or related methods, as this class sets up the flag and threshold.
---
2. TCS (Traction Control System)
• Purpose: Prevents excessive wheel spin during acceleration.
• Implementation:
• Controlled by the TCS boolean.
• Strength: TCSStrength (default 0.5).
• Behavior:
• When accelerating, the script checks for wheel slip.
• If slip exceeds TCSStrength, throttle or torque is reduced to regain traction.
• The flag TCSAct is set true when TCS is active.
• Note: Like ABS, the actual torque reduction is likely handled in wheel or engine logic.
---
3. ESP (Electronic Stability Program)
• Purpose: Maintains vehicle stability by correcting understeer/oversteer.
• Implementation:
• Controlled by the ESP boolean.
• Threshold: ESPThreshold (default 0.5), Strength: ESPStrength (default 0.25).
• Behavior:
• In ESPCheck():
• Calculates frontSlip and rearSlip from wheel colliders.
• If frontSlip exceeds ESPThreshold, sets underSteering = true.
• If rearSlip exceeds ESPThreshold, sets overSteering = true.
• If either is true, ESPAct = true and the system may apply corrective braking/torque.
• If ESPBroken is true, ESP is disabled.
• Note: Actual corrective actions are likely applied in the Wheels() method when ESPAct is true.
---
4. Steering Helper
• Purpose: Helps correct small steering errors and maintain intended direction.
• Implementation:
• Controlled by the steeringHelper boolean.
• Strengths: steerHelperLinearVelStrength, steerHelperAngularVelStrength.
• Behavior:
• In SteerHelper():
• Compares the vehicle’s velocity direction and steering direction.
• Applies a corrective torque to the Rigidbody to align the car’s movement with its steering.
• Adjusts linear velocity to reduce unwanted yaw.
• Only active when the car is grounded.
---
5. Traction Helper
• Purpose: Reduces over-rotation/spin at moderate slip angles.
• Implementation:
• Controlled by the tractionHelper boolean.
• Strength: tractionHelperStrength.
• Behavior:
• In TractionHelper():
• Calculates the angle between the car’s forward direction and its velocity.
• If the yaw angle and steering angle are opposed, reduces the sideways stiffness of the front wheels (via tractionHelpedSidewaysStiffness).
• This makes the car less likely to spin out at moderate slip angles.
---
6. Angular Drag Helper
• Purpose: Dynamically increases angular drag at higher speeds to reduce spin.
• Implementation:
• Controlled by the angularDragHelper boolean.
• Strength: angularDragHelperStrength.
• Behavior:
• In AngularDragHelper():
• Sets Rigid.angularDamping based on speed and the helper’s strength.
• Higher speeds result in more angular damping, making the car less likely to spin uncontrollably.
---
7. Steering Limiter & Counter-Steering
• Purpose:
• Steering Limiter: Reduces max steering input when sliding to prevent oversteer.
• Counter-Steering: Automatically applies counter-steer input when drifting.
• Implementation:
• Controlled by useSteeringLimiter and useCounterSteering.
• In SteeringAssistance():
• Calculates average sideways slip.
• If useSteeringLimiter is true, clamps steerInput based on slip.
• If useCounterSteering is true, sets counterSteerInput proportional to driftAngle and counterSteeringFactor.
---
8. Summary Table
| Feature | Toggle/Strength Fields | Main Method(s) | Effect | |---------------------|-------------------------------|------------------------|------------------------------------------------------------------------| | ABS | ABS, ABSThreshold | (Wheel logic) | Modulates brake to prevent lockup | | TCS | TCS, TCSStrength | (Wheel/engine logic) | Reduces torque to prevent wheel spin | | ESP | ESP, ESPThreshold, ESPStrength | ESPCheck, Wheels | Detects/corrects under/oversteer, applies corrective braking/torque | | Steering Helper | steeringHelper, steerHelper* | SteerHelper | Applies torque to align velocity and steering | | Traction Helper | tractionHelper, tractionHelperStrength | TractionHelper | Reduces front wheel grip to prevent spin at moderate slip | | Angular Drag Helper | angularDragHelper, angularDragHelperStrength | AngularDragHelper | Increases angular drag at high speed | | Steering Limiter | useSteeringLimiter | SteeringAssistance | Reduces max steering input when sliding | | Counter-Steering | useCounterSteering, counterSteeringFactor | SteeringAssistance | Adds counter-steer input when drifting |
---
In summary:
Each assist feature is modular, can be toggled or tuned, and works together to provide a realistic, stable, and user-friendly driving experience. The actual intervention (e.g., torque/brake modulation) is often handled in the wheel or engine logic, with this class orchestrating the detection and activation of each assist.
Changed files in this update