RUST · VEHICLE DYNAMICS

simplecar2-rs — Raycast Suspension, Anti-Roll Bar & Drivetrain Vehicle Physics in Rust

simplecar2-rs is a pure Rust vehicle dynamics crate designed for arcade-sim driving games and real-time simulations. It models 4-wheel raycast spring-damper suspension, lateral anti-roll bars, Ackermann steering geometry, and combustion or electric torque curves at over a million steps per second.

$ cargo add simplecar2-rs
GitHub ↗

Real-Time Vehicle Simulator

Experience the exact mathematical models implemented in simplecar2-rs executing directly in your browser.

Speed
0 km/h
Gear
1
Engine RPM
850
Powertrain Type Combustion (ICE)
Throttle Control (or Hold Spacebar) 0%
Transmission Shifter Automatic Shift
Driveshaft Ratio Calculation Ratio: 3.42 × 3.73 = 12.76:1
Clutch Capacity: 100% Engaged | Shift Delay: 0.0s
Chassis Lateral Roll / Cornering G-Force 0.00 G
Spring Stiffness ($k$) 35,000 N/m
Damper Coefficient ($c$) 3,200 N·s/m
Anti-Roll Bar (ARB) Stiffness ($k_{\text{arb}}$) 16,000 N/m
Axle Dynamic Normal Loads ($F_z$)
LEFT WHEEL
4,410 N
RIGHT WHEEL
4,410 N
Driver Steering Wheel Input ($\delta$) 0.0°
Speed-Sensitive Steering Attenuation 0 km/h (Full Lock)
Formula: $\delta_{\text{eff}} = \frac{\delta_{\text{max}} \cdot \text{input}}{1.0 + v \cdot k_{\text{speed}}}$
Ackermann Kinematics
INNER WHEEL
0.0°
OUTER WHEEL
0.0°
Turning Radius: ∞ (Straight)
Wheelbase: 2.65 m | Track Width: 1.62 m
Differential Architecture Limited Slip (LSD)
Tire Grip Disparity (Left on Ice vs Right on Asphalt) 50% / 50%
Input Driveshaft Torque 600 N·m
Delivered Wheel Torques
LEFT WHEEL TORQUE
300 N·m
RIGHT WHEEL TORQUE
300 N·m

Engineered For Performance

Every subsystem in simplecar2-rs operates as a decoupled, deterministic state machine ready for Bevy ECS and network rollback.

🛞

Raycast Suspension & ARBs

Simulates spring compression, bump & rebound damping, and anti-roll sway bar force transfer without expensive rigid body joint constraints.

$$F_N = k \cdot x - c \cdot v \pm k_{\text{arb}} \cdot (x_L - x_R)$$
⚡

Combustion & EV Drivetrains

Dual powertrain modes: accurate combustion engine RPM torque curves with rev limiters, or instant flat-torque electric motor profiles with regenerative braking.

$$P(t) = 0.3 + 0.7 \cdot t^2 \quad \text{for } RPM_{\text{idle}} \le RPM < RPM_{\text{peak}}$$
🕹️

Automatic Transmission

Multi-speed planetary or dual-clutch transmission with automatic upshift/downshift logic, rev-limiter safety overspeed shift, and shift torque cut.

$$R_{\text{total}} = R_{\text{gear}} \cdot R_{\text{final}}, \quad T_{\text{shaft}} = T_{\text{eng}} \cdot R_{\text{total}}$$
⚙️

Open, Locked & LSD Differentials

Configurable final drive split: 50/50 open differential, 100% spooled locked differential with normal load bias, or clutch-pack limited slip with speed delta lockup.

$$T_{\text{lock}} = \text{clamp}(k_{\text{lsd}} \Delta\omega + \text{sgn}(\Delta\omega) T_{\text{pre}}, -T_{\max}, T_{\max})$$
📐

True Ackermann Steering

Calculates exact distinct inner and outer wheel turn angles to trace concentric circles, with velocity-sensitive high speed steering lock reduction.

$$\delta_{\text{inner}} = \arctan\left(\frac{2L \tan\delta}{2L - W \tan\delta}\right)$$
🦀

Pure Rust & Zero Engine Lock-in

Built strictly on glam and serde. Easily drops into Bevy, Rapier, PhysX, or bespoke custom simulation pipelines with zero friction.

$$\text{glam::Vec3}, \quad \text{glam::Quat}, \quad \text{serde::Serialize}$$

Mathematical Rigor

The analytical physics models underlying the simplecar2-rs implementation.

Anti-Roll Bar Dynamics

When cornering, centrifugal force produces chassis roll angle $\phi$, compressing the outer wheel ($x_{\text{outer}}$) and extending the inner wheel ($x_{\text{inner}}$). The sway bar creates equal and opposite corrective normal forces:

$$\Delta x = x_{\text{left}} - x_{\text{right}}$$ $$F_{\text{arb}} = k_{\text{arb}} \cdot \Delta x$$ $$F_{N,\text{left}} = F_{\text{spring}} + F_{\text{damping}} - F_{\text{arb}}$$ $$F_{N,\text{right}} = F_{\text{spring}} + F_{\text{damping}} + F_{\text{arb}}$$

Clutch Torque Coupling

Torque transfer between engine flywheel ($\omega_{\text{engine}}$) and transmission input shaft ($\omega_{\text{trans}}$) uses hyperbolic tangent friction smoothing:

$$T_{\text{capacity}} = \gamma \cdot T_{\text{max\_clutch}}$$ $$T_{\text{clutch}} = T_{\text{capacity}} \cdot \tanh\left(0.1 \cdot (\omega_{\text{engine}} - \omega_{\text{trans}})\right)$$

Quick Start Guide

Drop simplecar2 into your Cargo.toml and initialize your vehicle state machine in seconds.

Cargo.toml
# Add to your dependencies
[dependencies]
simplecar2 = "0.1"
glam = "0.29"
main.rs
use glam::{Quat, Vec3};
use simplecar2::prelude::*;

fn main() {
    // 1. Configure vehicle chassis, suspension & powertrain
    let mut vehicle = Vehicle::new(VehicleConfig::default());

    // 2. Supply driver inputs
    let inputs = VehicleInputs {
        steer: 0.25,        // Steer angle [-1.0, 1.0]
        throttle: 0.85,     // 85% throttle
        brake: 0.0,
        handbrake: false,
        clutch_pedal: 0.0,  // Clutch engaged
    };

    // 3. Provide raycast contact results from physics world (Rapier, XPBD, etc.)
    let hits = [
        Some(WheelRaycastHit { distance: 0.40, point: Vec3::new(-0.81, 0.0, 1.35), normal: Vec3::Y }),
        Some(WheelRaycastHit { distance: 0.40, point: Vec3::new(0.81, 0.0, 1.35), normal: Vec3::Y }),
        Some(WheelRaycastHit { distance: 0.40, point: Vec3::new(-0.81, 0.0, -1.30), normal: Vec3::Y }),
        Some(WheelRaycastHit { distance: 0.40, point: Vec3::new(0.81, 0.0, -1.30), normal: Vec3::Y }),
    ];

    // 4. Advance physics step
    let forces = vehicle.step(
        &inputs, hits,
        Vec3::new(0.0, 0.45, 0.0),
        Quat::IDENTITY,
        Vec3::new(0.0, 0.0, 14.0),
        Vec3::ZERO,
        1.0 / 60.0,
    ).unwrap();

    println!("Total force: {:?}", forces.total_force);
    println!("Engine RPM: {:.0}", vehicle.engine_state.rpm);
}

Nanosecond Vehicle Dynamics vs. Godot GDScript

Comparative physics performance measuring full 4-wheel raycast suspension, drivetrain, and limited-slip differential. View Full BENCHMARKS.md →

Single Vehicle Step
206.4 ns / tick
896× faster than GDScript (~185 µs)
100-Car Fleet at 60 FPS
19.8 µs / frame
0.12% of 16.6ms 60 FPS frame budget
1,000-Car Massive Traffic
201.2 µs (4,971 FPS)
GDScript drops below 10 FPS (>180 ms)
Limited-Slip Diff Solve
3.62 ns / solve
276.6 Million solves/sec (Zero Alloc)

Automated Test Suite

100% pass rate across the full vehicle physics specification.

23 Tests Passed
0 failed · 0 ignored · 7 integration suites
✓ ALL TESTS PASSING
accuracy_test 3/3
✓ test_suspension_hooke_equilibrium_accuracy (ΔF = 0.04 N)
✓ test_ackermann_steering_kinematic_parity (Δ = 0.0002)
✓ test_open_differential_torque_parity (Exact IEEE 754)
differential_tests 3/3
✓ test_open_differential
✓ test_locked_differential
✓ test_limited_slip_differential
drivetrain_tests 4/4
✓ test_engine_power_curve
✓ test_clutch_torque_transfer
✓ test_constant_torque_mode
✓ test_engine_state_update
steering_tests 4/4
✓ test_ackermann_geometry_left_turn
✓ test_ackermann_geometry_right_turn
✓ test_speed_sensitive_steering_reduction
✓ test_steering_state_update_smoothing
suspension_tests 3/3
✓ test_suspension_spring_and_damping
✓ test_anti_roll_bar
✓ test_suspension_airborne
transmission_tests 4/4
✓ test_gear_ratios_and_total_ratio
✓ test_automatic_shifting_upshift_and_downshift
✓ test_manual_shifting
✓ test_rev_limiter_safety_upshift
vehicle_tests 2/2
✓ test_vehicle_initialization_and_grounded_step
✓ test_vehicle_acceleration_and_braking